Module: ActiveRecord
- Defined in:
- lib/active_record/union_relation.rb,
lib/active_record/union_relation/version.rb
Defined Under Namespace
Classes: UnionRelation
Class Method Summary collapse
-
.union(*columns, discriminator: 'discriminator') ⇒ Object
Unions require that you have an equal number of columns from each subquery.
Class Method Details
.union(*columns, discriminator: 'discriminator') ⇒ Object
Unions require that you have an equal number of columns from each subquery. The columns argument being passed here is any number of symbols that represent the columns that will be queried. When you then go to add sources into the union you’ll need to pass the same number of columns.
One additional column will be added to the query in order to discriminate between all of the unioned types. Then when the objects are going to be instantiated, we map the columns back to their original names.
132 133 134 |
# File 'lib/active_record/union_relation.rb', line 132 def self.union(*columns, discriminator: 'discriminator') UnionRelation.new(columns, discriminator).tap { |union| yield union }.all end |