brianhempel / active_record_union

UNIONs in ActiveRecord! Adds proper union and union_all methods to ActiveRecord::Relation.
Other
423 stars 41 forks source link

nil.union(something_not_nil) #17

Closed Alagaesia93 closed 7 years ago

Alagaesia93 commented 7 years ago

I suppose it's not a bug, but maybe someone has found a workaround.

I have 6 objects initialised with 6 total different queries and I want to chain unions.

obj1.union(obj2).union(obj3) and so on

Each one can be nil, and I want to union all the results. There is no default (otherwise I could use default_obj.union(obj1) and so on).

Any ideas?

brianhempel commented 7 years ago
[query1, query2, query3, query4, query5, query6].compact.reduce(:union)