Class: ROM::SQL::Association::OneToMany
- Inherits:
-
ROM::SQL::Association
- Object
- ROM::SQL::Association
- ROM::SQL::Association::OneToMany
- Defined in:
- lib/rom/sql/association/one_to_many.rb
Direct Known Subclasses
Instance Method Summary collapse
- #associate(relations, child, parent) ⇒ Object private
- #call(relations, right = relations[target.relation]) ⇒ Object
- #combine_keys(relations) ⇒ Object
- #join_keys(relations) ⇒ Object
Instance Method Details
#associate(relations, child, parent) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 |
# File 'lib/rom/sql/association/one_to_many.rb', line 35 def associate(relations, child, parent) pk, fk = join_key_map(relations) child.merge(fk => parent.fetch(pk)) end |
#call(relations, right = relations[target.relation]) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rom/sql/association/one_to_many.rb', line 8 def call(relations, right = relations[target.relation]) schema = right.schema.qualified relation = right .inner_join(source_table, join_keys(relations)) .order(*right.schema.project_pk.qualified) if view apply_view(schema, relation) else schema.(relation) end end |
#combine_keys(relations) ⇒ Object
23 24 25 |
# File 'lib/rom/sql/association/one_to_many.rb', line 23 def combine_keys(relations) Hash[*with_keys(relations)] end |
#join_keys(relations) ⇒ Object
28 29 30 31 32 |
# File 'lib/rom/sql/association/one_to_many.rb', line 28 def join_keys(relations) with_keys(relations) { |source_key, target_key| { qualify(source_alias, source_key) => qualify(target, target_key) } } end |