Class: ActiveData::Model::Associations::EmbedsMany
- Inherits:
-
Association
- Object
- Association
- ActiveData::Model::Associations::EmbedsMany
show all
- Defined in:
- lib/active_data/model/associations/embeds_many.rb
Instance Attribute Summary
Attributes inherited from Association
#klass, #name, #options
Instance Method Summary
collapse
Methods inherited from Association
#class_name, #define_accessor, #initialize
Instance Method Details
#collection? ⇒ Boolean
6
7
8
|
# File 'lib/active_data/model/associations/embeds_many.rb', line 6
def collection?
true
end
|
#define_reader(target) ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/active_data/model/associations/embeds_many.rb', line 10
def define_reader target
target.class_eval <<-EOS
def #{name}
@#{name} ||= begin
association = self.class.reflect_on_association('#{name}')
association.klass.collection
end
end
EOS
end
|
#define_writer(target) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/active_data/model/associations/embeds_many.rb', line 21
def define_writer target
target.class_eval <<-EOS
def #{name}= value
association = self.class.reflect_on_association('#{name}')
@#{name} = association.klass.collection(value)
end
EOS
end
|