Ruby on Rails 3 howto make 'OR' condition

前端 未结 9 1373
無奈伤痛
無奈伤痛 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条回答
  •  -上瘾入骨i
    2020-12-03 01:24

    Sadly, the .or isn't implemented yet (but when it is, it'll be AWESOME).

    So you'll have to do something like:

    class Project < ActiveRecord::Base
      scope :sufficient_data, :conditions=>['ratio_story_completion != 0 OR ratio_differential != 0']
      scope :profitable, :conditions=>['profit > 0']
    

    That way you can still be awesome and do:

    Project.sufficient_data.profitable
    

提交回复
热议问题