开发者

Exclude id in rails scope

开发者 https://www.devze.com 2023-04-02 12:48 出处:网络
How can I exclude some items in this scope: s开发者_开发问答cope :within_category, ->(category) { joins(:category).where(:categories => { :id => category }) }

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) }
0

精彩评论

暂无评论...
验证码 换一张
取 消