Class: ROM::SQL::Association::OneToOne

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

Direct Known Subclasses

OneToMany

Instance Attribute Summary

Attributes inherited from ROM::SQL::Association

#as, #relation, #result, #source, #target

Instance Method Summary collapse

Methods inherited from ROM::SQL::Association

#initialize, #qualify

Constructor Details

This class inherits a constructor from ROM::SQL::Association

Instance Method Details

#call(relations) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rom/sql/association/one_to_one.rb', line 8

def call(relations)
  with_keys(relations) do |left_pk, right_fk|
    right = relations[target.relation]
    columns = right.header.qualified.to_a

    relation = right
      .inner_join(source, left_pk => right_fk)
      .select(*columns)
      .order(*right.header.project(*right.primary_key).qualified)

    relation.with(attributes: relation.header.names)
  end
end

#combine_keys(relations) ⇒ Object



23
24
25
# File 'lib/rom/sql/association/one_to_one.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_one.rb', line 28

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