Chaining Named Scopes not working as intended

后端 未结 1 435
温柔的废话
温柔的废话 2021-01-14 10:56

I have 2 simple named scopes defined as such:

class Numbers < ActiveRecord::Base
  named_scope :even, :conditions => {:title => [\'2\',\'4\',\'6\']}         


        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 11:28

    It's an issue with how ActiveRecord handles scopes. When you apply multiple scopes, the results are joined together with AND. There is no option for using OR.

    What you need to do instead is combine two result sets:

    Numbers.even.all + Numbers.odd.all
    

    0 讨论(0)
提交回复
热议问题