2010-02-21 2 views
0
class Promotion 
def self.get_todays_promotions 
    # Promotion is a parent model, having child models e.g. 
    # DiscountPromotion, VoucherPromotion, etc. 
    # they all use a single table called promotions 
    # (and having 'type' field explaining which model they belong to) 
    promotions = self.find(:all, :conditions => [Promotion.date_check_query], :order => "#{Promotion.table_name}.order_of_calculation") 

    # Normally promotions would contain a collection of Promotion models. 
    # I want to return a collection of various models here depending on 
    # each model's class name 
    end 
end 

위 작업을 수행 할 수 있습니까?Ruby Activescaffold로 다양한 모델을 반환하려고하면 상속 모델을 찾으십시오

감사합니다.

+0

내 테스트에서 이것은 간단하게 작동하며'type' 필드의 내용에 따라'DiscountPromotion' 또는'VoucherPromotion'을 얻습니다. 아마도 당신은 당신의 스키마와 서브 클래스가 어떻게 생겼는지를 포함하여 잘못된 일이 무엇인지에 대한보다 완벽한 예를 제시 할 수있을 것입니다. –

+0

네 말이 맞아, 그냥 작동! 죄송합니다. 단지 실수였습니다. 제대로 테스트하지 않았습니다 ... – jaycode

답변

0

는 위의 의견으로 대답했습니다.

관련 문제