2011-09-04 53 views
2

,如何排除在此范围内的一些项目:排除ID在轨道范围

scope :within_category, ->(category) { joins(:category).where(:categories => { :id => category }) }

这样的:

scope :within_category, ->(category, item_type) { joins(:category).where(:categories => { :id => category }, :id NOT IN item_type.id) } 

回答

5

试试这个:

scope :within_category, ->(category, item_type) { joins(:category).where(:categories => { :id => category }).where(self.arel_table[:id].not_in(item_type.id) }