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

Is it possible to do the above?

Thank you!

jaycode
  • 2,926
  • 5
  • 35
  • 71
  • In my testing, this simply works, and I get a `DiscountPromotion` or `VoucherPromotion` depending on what's in the `type` field. Perhaps you can give a more complete example of what's going wrong, including what your schema and subclasses look like? – Stéphan Kochen Feb 21 '10 at 17:49
  • You are right, it just works! sorry it was just a mistake - I haven't tested it properly... – jaycode Feb 22 '10 at 06:15

1 Answers1

0

answered as the comment above.

jaycode
  • 2,926
  • 5
  • 35
  • 71