Module: Torque::PostgreSQL::Relation::CrossJoin
- Included in:
- ActiveRecord::Relation
- Defined in:
- lib/torque/postgresql/relation/cross_join.rb,
sig/torque/postgresql/relation/cross_join.rbs
Defined Under Namespace
Modules: Merger Classes: Entry
Class Method Summary collapse
-
.build(source, as, columns, mode, with_ordinality, definitions = nil) ⇒ Entry
Assemble the join node and the table that stands for what it exposes, which is what makes the result reachable by name.
Instance Method Summary collapse
-
#cross_join(source, **xargs) ⇒ relation
Joins the query against a set produced by the given source, which can be an Arel node, another relation, or a list of rows.
-
#cross_join!(source, as:, columns: nil, mode: :cross, with_ordinality: false) ⇒ self
Like #cross_join, but modifies relation in place.
-
#cross_joins_value ⇒ Hash[Symbol, Entry]
:nodoc:.
-
#cross_joins_value=(value) ⇒ Hash[Symbol, Entry]
:nodoc:.
Class Method Details
.build(source, as, columns, mode, with_ordinality, definitions = nil) ⇒ Entry
Assemble the join node and the table that stands for what it exposes, which is what makes the result reachable by name
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/torque/postgresql/relation/cross_join.rb', line 13 def build(source, as, columns, mode, with_ordinality, definitions = nil) columns = columns_for(source, columns) ordinality = ordinality_for(with_ordinality) validate_ordinality!(ordinality, columns, definitions) source, lateral = source_for(source, columns) item = Arel::Nodes::FromItem.new(source, as, columns: columns, definitions: definitions, ordinality: ordinality, lateral: lateral) Entry.new(join_for(mode, item), ::Arel::Table.new(as.to_s)) end |
Instance Method Details
#cross_join(source, **xargs) ⇒ relation
Joins the query against a set produced by the given source, which
can be an Arel node, another relation, or a list of rows. The result
is reachable by the name given to as. For example:
User.cross_join(FN.generate_series(1, 5), as: :sample, columns: %i[value])
# Returns 5 rows for each user
User.cross_join([{ id: 1, label: 'a' }], as: :labels)
# Returns the rows of the list combined with each user
139 140 141 |
# File 'lib/torque/postgresql/relation/cross_join.rb', line 139 def cross_join(source, **xargs) spawn.cross_join!(source, **xargs) end |
#cross_join!(source, as:, columns: nil, mode: :cross, with_ordinality: false) ⇒ self
Like #cross_join, but modifies relation in place.
144 145 146 147 148 |
# File 'lib/torque/postgresql/relation/cross_join.rb', line 144 def cross_join!(source, as:, columns: nil, mode: :cross, with_ordinality: false) entry = CrossJoin.build(source, as, columns, mode, with_ordinality) self.cross_joins_value = cross_joins_value.merge(as.to_sym => entry) self end |
#cross_joins_value ⇒ Hash[Symbol, Entry]
:nodoc:
120 121 122 |
# File 'lib/torque/postgresql/relation/cross_join.rb', line 120 def cross_joins_value @values.fetch(:cross_joins, ::ActiveRecord::QueryMethods::FROZEN_EMPTY_HASH) end |
#cross_joins_value=(value) ⇒ Hash[Symbol, Entry]
:nodoc:
125 126 127 128 |
# File 'lib/torque/postgresql/relation/cross_join.rb', line 125 def cross_joins_value=(value) assert_modifiable! @values[:cross_joins] = value end |