2011-09-04 50 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) }