Exclude id in rails scope
How can I exclude some items in this scope:
s开发者_开发问答cope :within_category, ->(category) { joins(:category).where(:categories => { :id => category }) }
like this:
scope :within_category, ->(category, item_type) { joins(:category).where(:categories => { :id => category }, :id NOT IN item_type.id) }
Try this:
scope :within_category, ->(category, item_type) { joins(:category).where(:categories => { :id => category }).where(self.arel_table[:id].not_in(item_type.id) }
精彩评论