Class: Her::Model::Associations::BelongsToAssociation
- Inherits:
-
Association
- Object
- Association
- Her::Model::Associations::BelongsToAssociation
- Defined in:
- lib/castle-her/model/associations/belongs_to_association.rb
Instance Method Summary collapse
-
#build(attributes = {}) ⇒ Object
Initialize a new object.
-
#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
48 49 50 |
# File 'lib/castle-her/model/associations/belongs_to_association.rb', line 48 def build(attributes = {}) @klass.build(attributes) end |
#create(attributes = {}) ⇒ Object
Create a new object, save it and associate it to the parent
67 68 69 70 71 |
# File 'lib/castle-her/model/associations/belongs_to_association.rb', line 67 def create(attributes = {}) resource = build(attributes) @parent.attributes[@name] = resource if resource.save resource end |