Ruby on Rails 3 howto make 'OR' condition

前端 未结 9 1376
無奈伤痛
無奈伤痛 2020-12-03 00:34

I need an SQL statement that check if one condition is satisfied:

SELECT * FROM my_table WHERE my_table.x=1 OR my_table.y=1

I want to do th

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 01:24

    Those arel queries are unreadable to me.

    What's wrong with a SQL string? In fact, the Rails guides exposes this way as the first way to make conditions in queries: http://guides.rubyonrails.org/active_record_querying.html#array-conditions

    So, I bet for this way to do it as the "Rails way":

    Account.where("id = 1 OR id = 2")
    

    In my humble opinion, it's shorter and clearer.

提交回复
热议问题