Method: Her::Model::Associations::BelongsToAssociation#create

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

#create(attributes = {}) ⇒ Object

Create a new object, save it and associate it to the parent

Examples:

class User
  include Her::Model
  belongs_to :organization
end

class Organization
  include Her::Model
end

user = User.find(1)
user.organization.create(:name => "Foo Inc.")
user.organization # => #<Organization id=2 name="Foo Inc.">


66
67
68
69
70
# File 'lib/her/model/associations/belongs_to_association.rb', line 66

def create(attributes = {})
  resource = build(attributes)
  @parent.attributes[@name] = resource if resource.save
  resource
end