Method: ReactiveResource::Association::HasManyAssociation#add_helper_methods
- Defined in:
- lib/reactive_resource/association/has_many_association.rb
#add_helper_methods(klass, attribute) ⇒ Object
Adds methods for has_many associations, to make dealing with these objects a bit more straightforward. If the attribute name is lawyers, it will add:
- lawyers
-
returns the associated lawyers
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/reactive_resource/association/has_many_association.rb', line 38 def add_helper_methods(klass, attribute) association = self klass.class_eval do # lawyer.addresses define_method(attribute) do unless instance_variable_get("@#{attribute}") object = association.resolve_relationship(self) instance_variable_set("@#{attribute}", object) end instance_variable_get("@#{attribute}") end end end |