Class: ROM::SQL::Associations::ManyToOne

Inherits:
Associations::ManyToOne
  • Object
show all
Includes:
SelfRef
Defined in:
lib/rom/sql/associations/many_to_one.rb

Instance Method Summary collapse

Instance Method Details

#call(target: self.target, preload: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rom/sql/associations/many_to_one.rb', line 15

def call(target: self.target, preload: false)
  if preload
    schema = target.schema.qualified
    relation = target
  else
    right = source

    target_pk = target.schema.primary_key_name
    right_fk = target.foreign_key(source.name)

    target_schema = target.schema
    right_schema = right.schema.project_pk

    schema =
      if target.schema.key?(right_fk)
        target_schema
      else
        target_schema.merge(right_schema.project_fk(target_pk => right_fk))
      end.qualified

    relation = target.join(source_table, join_keys)
  end

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

#join(type, source = self.source, target = self.target) ⇒ Object



46
47
48
# File 'lib/rom/sql/associations/many_to_one.rb', line 46

def join(type, source = self.source, target = self.target)
  source.__send__(type, target.name.dataset, join_keys).qualified
end

#join_keysObject Originally defined in module SelfRef

#source_attrObject Originally defined in module SelfRef

#target_attrObject Originally defined in module SelfRef