Class: SimpleMaster::Master::Association::HasManyAssociation
Instance Attribute Summary
#defined_at, #name, #options
Instance Method Summary
collapse
#initialize, #is_active_record?, #target_class
Instance Method Details
#foreign_key ⇒ Object
7
8
9
|
# File 'lib/simple_master/master/association/has_many_association.rb', line 7
def foreign_key
@foreign_key ||= (options[:foreign_key] || ActiveSupport::Inflector.foreign_key(defined_at.to_s)).to_sym
end
|
#init(master_class) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/simple_master/master/association/has_many_association.rb', line 19
def init(master_class)
master_class.simple_master_module.class_eval <<-RUBY, __FILE__, __LINE__ + 1
if #{target_class} < SimpleMaster::Master
def #{name}
#{target_class}.all_by(:#{foreign_key}, #{primary_key})
end
else
def #{name}
has_many_store[:#{name}] ||= #{target_class}.simple_master_connection.where(:#{foreign_key} => #{primary_key}).to_a
end
end
RUBY
end
|
#init_for_test(master_class) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/simple_master/master/association/has_many_association.rb', line 33
def init_for_test(master_class)
master_class.simple_master_module.class_eval <<-RUBY, __FILE__, __LINE__ + 1
if #{target_class} < SimpleMaster::Master
def #{name}
has_many_store[:#{name}] || #{target_class}.all_by(:#{foreign_key}, #{primary_key})
end
else
def #{name}
has_many_store[:#{name}] ||= #{target_class}.simple_master_connection.where(:#{foreign_key} => #{primary_key}).to_a
end
end
def #{name}=(values)
has_many_store[:#{name}] = values
end
RUBY
end
|
#inverse_of ⇒ Object
11
12
13
|
# File 'lib/simple_master/master/association/has_many_association.rb', line 11
def inverse_of
@inverse_of ||= options[:inverse_of] || ActiveSupport::Inflector.underscore(defined_at.to_s)
end
|
#primary_key ⇒ Object
15
16
17
|
# File 'lib/simple_master/master/association/has_many_association.rb', line 15
def primary_key
@primary_key ||= options[:primary_key] || defined_at.primary_key || :id
end
|