如何排除此范围内的某些项目:
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) }
答案 0 :(得分:5)
试试这个:
scope :within_category, ->(category, item_type) { joins(:category).where(:categories => { :id => category }).where(self.arel_table[:id].not_in(item_type.id) }