Class: ActiveForce::Association::Association
- Inherits:
-
Object
- Object
- ActiveForce::Association::Association
show all
- Extended by:
- Forwardable
- Defined in:
- lib/active_force/association/association.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent, relation_name, options = {}) ⇒ Association
Returns a new instance of Association.
9
10
11
12
13
14
15
|
# File 'lib/active_force/association/association.rb', line 9
def initialize parent, relation_name, options = {}
@parent = parent
@relation_name = relation_name
@options = options
define_relation_method
define_assignment_method
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7
8
9
|
# File 'lib/active_force/association/association.rb', line 7
def options
@options
end
|
#relation_name ⇒ Object
Returns the value of attribute relation_name.
7
8
9
|
# File 'lib/active_force/association/association.rb', line 7
def relation_name
@relation_name
end
|
Instance Method Details
#foreign_key ⇒ Object
21
22
23
|
# File 'lib/active_force/association/association.rb', line 21
def foreign_key
options[:foreign_key] || default_foreign_key
end
|
#load_target(owner) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/active_force/association/association.rb', line 50
def load_target(owner)
if loadable?(owner)
target(owner)
else
target_when_unloadable
end
end
|
#relation_model ⇒ Object
17
18
19
|
# File 'lib/active_force/association/association.rb', line 17
def relation_model
(options[:model] || relation_name.to_s.singularize.camelcase).to_s.constantize
end
|
#relationship_name ⇒ Object
25
26
27
|
# File 'lib/active_force/association/association.rb', line 25
def relationship_name
options[:relationship_name] || relation_model.to_s.constantize.table_name
end
|
#represents_sfdc_table?(sfdc_table_name) ⇒ Boolean
Does this association’s relation_model represent sfdc_table_name
? Examples of sfdc_table_name
could be ‘Quota__r’ or ‘Account’.
41
42
43
44
|
# File 'lib/active_force/association/association.rb', line 41
def represents_sfdc_table?(sfdc_table_name)
name = sfdc_table_name.sub(/__r\z/, '').singularize
relationship_name.sub(/__c\z|__r\z/, '') == name
end
|
#scoped? ⇒ Boolean
33
34
35
|
# File 'lib/active_force/association/association.rb', line 33
def scoped?
options[:scoped_as].present?
end
|
#scoped_as ⇒ Object
29
30
31
|
# File 'lib/active_force/association/association.rb', line 29
def scoped_as
options[:scoped_as] || nil
end
|
#sfdc_association_field ⇒ Object
46
47
48
|
# File 'lib/active_force/association/association.rb', line 46
def sfdc_association_field
relationship_name.gsub /__c\z/, '__r'
end
|