Does Rails 4 have support for OR queries

前端 未结 7 1946
暗喜
暗喜 2020-12-08 13:14

So in Rails 4 the long desired feature to use not queries has been added.

Article.where.not(title: \'Rails 3\')

Has similar su

7条回答
  •  旧时难觅i
    2020-12-08 13:36

    Article.where(title: ['Rails 3', 'Rails 4'])
    

    is how you'd do that in Active Record.

    It's not possible to replicate any arbitrary SQL query using "Rails-y" syntax. But you can always just pass in literal sql.

    So you could also do:

    Article.where("articles.title = 'Rails 3' OR articles.title = 'Rails 4'")
    

提交回复
热议问题