开发者

Using greater than 0 in a find(:all, :conditions =>{}) statement in rails

开发者 https://www.devze.com 2023-02-22 10:39 出处:网络
I\'m trying (and failing) to construct a find all statement with conditions in rails for what I need. I need to find a开发者_如何转开发ll the values where where the \'in\' value in a table is greater

I'm trying (and failing) to construct a find all statement with conditions in rails for what I need. I need to find a开发者_如何转开发ll the values where where the 'in' value in a table is greater than 0 (or just not zero would be fine) but I am having trouble with this, here's what I need:

@sales = Transaction.find(:all, :conditions => {:in => 'greater than 0'} )

Is there a simple way to do this?

Thanks,

Tom


You can use Arel to do this without having to reach into SQL:

@sales = Transaction.where(Transaction.arel_table[:in].gt(0)).all


Try this

  @sales = Transaction.find(:all, :conditions => ['in > ?', 0] )

OR use conditions like

  :conditions => 'in > 0'
0

精彩评论

暂无评论...
验证码 换一张
取 消