尝试使用Ruby Activescaffold返回各种模型,在具有继承的模型上查找

尝试使用Ruby Activescaffold返回各种模型,在具有继承的模型上查找,ruby,inheritance,find,single-table-inheritance,Ruby,Inheritance,Find,Single Table Inheritance,有可能做到以上几点吗 谢谢大家! 回答如上所述。在我的测试中,这很有效,我会得到折扣促销或凭证促销,具体取决于类型字段中的内容。也许你可以给出一个更完整的例子来说明哪里出了问题,包括你的模式和子类是什么样子的?你是对的,它很有效!抱歉,这只是一个错误-我没有正确测试它。。。 class Promotion def self.get_todays_promotions # Promotion is a parent model, having child models e.g.

有可能做到以上几点吗


谢谢大家!

回答如上所述。

在我的测试中,这很有效,我会得到
折扣促销
凭证促销
,具体取决于
类型
字段中的内容。也许你可以给出一个更完整的例子来说明哪里出了问题,包括你的模式和子类是什么样子的?你是对的,它很有效!抱歉,这只是一个错误-我没有正确测试它。。。
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