我一直在试图找出如何正确使用以下示例的作用域。Rails 3 - 多态和全局作用域
有一张表具有多项式关联到项目的注释。但我也允许有“全局”注释,所以当我在Notes上进行作用域时,我希望它将多形关联返回到Items和NULL多形态域,以及其他一些条件,如IsReviewed类型布尔值。我试图做到以下几点,但效果不佳。
scope :is_reviewed, lambda { { :include => [:category, :notable], :conditions => ["is_reviewed = ?", true] } }
,然后尝试,但不会返回 “全球一”
scope :is_reviewed, lambda { { :include => [:category, :notable], :conditions => ["notable_type = 'Item' and is_reviewed = ?", true] } }
和尝试,但似乎并没有正常工作
scope :is_reviewed, lambda { { :include => [:category, :notable], :conditions => ["(notable_type = 'Item' or notable_type = NULL) and is_reviewed = ?", true] } }
任何想法或帮助将不胜感激。谢谢