Class: ROM::SQL::Association::OneToMany

Inherits:
ROM::SQL::Association show all
Defined in:
lib/rom/sql/association/one_to_many.rb

Direct Known Subclasses

OneToOne

Instance Method Summary collapse

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.



33
34
35
36
# File 'lib/rom/sql/association/one_to_many.rb', line 33

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
# 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))

  if view
    apply_view(schema, relation)
  else
    schema.(relation)
  end
end

#combine_keys(relations) ⇒ Object



21
22
23
# File 'lib/rom/sql/association/one_to_many.rb', line 21

def combine_keys(relations)
  Hash[*with_keys(relations)]
end

#join_keys(relations) ⇒ Object



26
27
28
29
30
# File 'lib/rom/sql/association/one_to_many.rb', line 26

def join_keys(relations)
  with_keys(relations) { |source_key, target_key|
    { qualify(source_alias, source_key) => qualify(target, target_key) }
  }
end