Class: Her::Model::Associations::HasOneAssociation
- Inherits:
-
Association
- Object
- Association
- Her::Model::Associations::HasOneAssociation
- Defined in:
- lib/castle-her/model/associations/has_one_association.rb
Instance Method Summary collapse
-
#build(attributes = {}) ⇒ Object
Initialize a new object with a foreign key to the parent.
-
#create(attributes = {}) ⇒ Object
Create a new object, save it and associate it to the parent.
Methods inherited from Association
Instance Method Details
#build(attributes = {}) ⇒ Object
Initialize a new object with a foreign key to the parent
47 48 49 |
# File 'lib/castle-her/model/associations/has_one_association.rb', line 47 def build(attributes = {}) @klass.build(attributes.merge(:"#{@parent.singularized_resource_name}_id" => @parent.id)) end |
#create(attributes = {}) ⇒ Object
Create a new object, save it and associate it to the parent
66 67 68 69 70 |
# File 'lib/castle-her/model/associations/has_one_association.rb', line 66 def create(attributes = {}) resource = build(attributes) @parent.attributes[@name] = resource if resource.save resource end |