Suppose I have the following two objects:
first_name_relation = User.where(:first_name => 'Tobias') # ActiveRecord::Relation
last_name_relation = User.where(:last_name => 'Fünke') # ActiveRecord::Relation
is it possible to combine the two relations to produce one ActiveRecord::Relation object containing both conditions?
Note: I’m aware that I can chain the wheres to get this behavior, what I’m really interested in is the case where I have two separate ActiveRecord::Relation objects.
If you want to combine using
AND(intersection), usemerge:If you want to combine using
OR(union), useor†:† Only in ActiveRecord 5+; for 4.2 install the where-or backport.