Class: Spyke::Associations::HasMany

Inherits:
Association show all
Defined in:
lib/spyke/associations/has_many.rb

Instance Attribute Summary

Attributes inherited from Association

#name, #parent

Attributes inherited from Relation

#klass, #params

Instance Method Summary collapse

Methods inherited from Association

#create, #new

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

#loadObject



10
11
12
# File 'lib/spyke/associations/has_many.rb', line 10

def load
  self
end