Class: Filemaker::Model::Relations::BelongsTo

Inherits:
Proxy
  • Object
show all
Defined in:
lib/filemaker/model/relations/belongs_to.rb

Instance Attribute Summary

Attributes inherited from Proxy

#options, #owner, #target

Instance Method Summary collapse

Methods inherited from Proxy

init, #method_missing, #respond_to_missing?, #target_class

Constructor Details

#initialize(owner, name, options) ⇒ BelongsTo

Returns a new instance of BelongsTo.



7
8
9
10
# File 'lib/filemaker/model/relations/belongs_to.rb', line 7

def initialize(owner, name, options)
  super(owner, name, options)
  build_target
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Filemaker::Model::Relations::Proxy

Instance Method Details

#final_reference_keyObject

Order: source_key first, reference_key next, then identity all must be findable using ‘find_field_by_name`



26
27
28
29
30
# File 'lib/filemaker/model/relations/belongs_to.rb', line 26

def final_reference_key
  target_class.find_field_by_name(source_key).try(:name) ||
    target_class.find_field_by_name(reference_key).try(:name) ||
    target_class.identity.try(:name)
end

#reference_keyObject



12
13
14
# File 'lib/filemaker/model/relations/belongs_to.rb', line 12

def reference_key
  options.fetch(:reference_key) { "#{@name}_id" }
end

#reference_valueObject



20
21
22
# File 'lib/filemaker/model/relations/belongs_to.rb', line 20

def reference_value
  owner.public_send(reference_key.to_sym)
end

#source_keyObject



16
17
18
# File 'lib/filemaker/model/relations/belongs_to.rb', line 16

def source_key
  options.fetch(:source_key) { nil }
end