Class: Spyke::Associations::HasMany
- Inherits:
-
Association
- Object
- Relation
- Association
- Spyke::Associations::HasMany
- Defined in:
- lib/spyke/associations/has_many.rb
Instance Attribute Summary
Attributes inherited from Association
Attributes inherited from Relation
Instance Method Summary collapse
- #assign_nested_attributes(incoming) ⇒ Object
-
#initialize(*args) ⇒ HasMany
constructor
A new instance of HasMany.
- #load ⇒ Object
Methods inherited from Association
Methods inherited from Relation
#each, #find, #find_one, #find_some, #uri, #where, #with, #with_fallback
Constructor Details
#initialize(*args) ⇒ HasMany
Returns a new instance of HasMany.
4 5 6 7 8 |
# File 'lib/spyke/associations/has_many.rb', line 4 def initialize(*args) super @options.reverse_merge!(uri: "#{parent_path}/:#{foreign_key}/#{@name}/(:#{primary_key})") @params[foreign_key] = parent.id end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Spyke::Relation
Instance Method Details
#assign_nested_attributes(incoming) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/spyke/associations/has_many.rb', line 14 def assign_nested_attributes(incoming) incoming = incoming.values if incoming.is_a?(Hash) combined_attributes = combine_with_existing(incoming) clear_existing! combined_attributes.each do |attributes| build(attributes) end end |
#load ⇒ Object
10 11 12 |
# File 'lib/spyke/associations/has_many.rb', line 10 def load self end |