Home > OS >  Rails5: convert find(:all, condition...) into "where"
Rails5: convert find(:all, condition...) into "where"

Time:10-17

(I'm so tired of asking these how to convert x into y questions)

How do I convert this deprecated rails 2 line

 Program.find(:all, :conditions => {:volunteer => true})]

into a "where" statement for Rails 5?

 Program.find(:all, where(:volunteer => true))]

...is not working.

Also, is there a source that has many many examples of converting "conditions" to "where"?

CodePudding user response:

If volunteer is a column on program you want

Program.where(volunteer: true)

no find needed. The active record docs are a good reference https://guides.rubyonrails.org/active_record_querying.html

I've only written rails 5/6. But I use

Model.find(id) # find exactly one
Model.find_by(column: value, column2: val2) # find exactly one by other cols
Model.where(col: val) # find 0 to many models by columns value
  • Related