Builds the relation depending on the attributes and the options passed to the macro.
This attempts to perform 3 operations, either one of an update of the existing relation, a replacement of the relation with a new document, or a removal of the relation.
Example:
one.build(person)
Options:
parent: The parent document of the relation.
# File lib/mongoid/relations/builders/nested_attributes/one.rb, line 23 def build(parent) return if reject?(parent, attributes) @existing = parent.send(metadata.name) if update? existing.attributes = attributes elsif replace? parent.send(metadata.setter, Mongoid::Factory.build(metadata.klass, attributes)) elsif delete? parent.send(metadata.setter, nil) end end
Create the new builder for nested attributes on one-to-one relations.
Example:
One.new(metadata, attributes, options)
Options:
metadata: The relation metadata attributes: The attributes hash to attempt to set. options: The options defined.
Returns:
A new builder.
# File lib/mongoid/relations/builders/nested_attributes/one.rb, line 51 def initialize(metadata, attributes, options) @attributes = attributes.with_indifferent_access @metadata = metadata @options = options @destroy = @attributes.delete(:_destroy) end
Generated with the Darkfish Rdoc Generator 2.