【问题标题】:Exclude id in rails scope在 rails 范围内排除 id
【发布时间】:2011-09-04 09:49:51
【问题描述】:

如何排除此范围内的某些项目:

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

【问题讨论】:

    标签: ruby-on-rails activerecord scope


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      相关资源
      最近更新 更多