Method: Her::Model::Associations::HasManyAssociation#build

Defined in:
lib/her/model/associations/has_many_association.rb

#build(attributes = {}) ⇒ Object

Initialize a new object with a foreign key to the parent

TODO: This only merges the id of the parents, handle the case

where this is more deeply nested

Examples:

class User
  include Her::Model
  has_many :comments
end

class Comment
  include Her::Model
end

user = User.find(1)
new_comment = user.comments.build(:body => "Hello!")
new_comment # => #<Comment user_id=1 body="Hello!">


54
55
56
# File 'lib/her/model/associations/has_many_association.rb', line 54

def build(attributes = {})
  @klass.build(attributes.merge(:"#{@parent.singularized_resource_name}_id" => @parent.id))
end