For example, I’d like to combine two arrays and add the where clause like so:
(Recipe.current + Recipe.previous).where(:name => “ABC”)
I know that you can combine it into one (Recipe.where(“current is true or previous is true”)), but I have a few complex queries that forces me to combine the arrays in the manner above.
Is it possible?
The answer depends on how many database queries you want to run to get the information.
If it’s okay to have 2 database queries, you might do something like this:
If you want to have it all in 1 database query, you have to use an
ORclause in your relation, unless you want to go beyond the regular ActiveRecord methods and use Arel or one of the query generation gems.