it works:
ids = [1,2] varietals = Varietal.find(:all, :conditions => [ "id IN (?)",ids])
But I want to say that the plus has a condition: deleted => false
varietals = Varietal.find(:all, :conditions =>{ :deleted => false})
any ideas?
Do I have to use find_by_sql?
You can do this in several ways, but it is most straightforward:
varietals = Varietal.find( [1,2], :conditions => { :deleted => false })
You can see in the docs that the first parameter findcan take an integer or an array.
find
I would handle this with named_scope to communicate intentions and facilitate reuse:
named_scope :undeleted, :conditions => { :deleted => false }
Then you can simply use:
varietals = Varietal.undeleted.find([1,2])
ids = [1,2] varietals = Varietal.find(:all, :conditions => {:id => ids, :deleted => false})
, .
docs:
SQL IN:
Student.find(:all, :conditions => { :grade => [9,11,12] })
Source: https://habr.com/ru/post/1727908/More articles:Android detects that activity is at the top of the history stack - androidHadoop pig Latin style guide? - coding-styleManaging SASS files in Git version control in Ruby on Rails - gitцвет границы не изменится - javascriptC # minimal tree implementation - c #UIActionSheet takes longer to download - iphoneUsing Asterisk in Objective-C - cЯвляется ли этот правильный способ обработать RESTful как URL-адрес в Lift Framework? - scalabesides the syntax of framework and java, what else is needed for mastering? - javaIs it possible to add a DataField to a Silverlight DataForm without creating an entire editing template? - silverlightAll Articles