Method: VirtualBox::AbstractModel#populate_attributes
- Defined in:
- lib/virtualbox/abstract_model.rb
#populate_attributes(attribs, opts = {}) ⇒ Object
Sets the initial attributes from a hash. This method is meant to be used once to initially setup the attributes. It is **not a mass-assignment** method for updating attributes.
This method does not affect dirtiness, but also does not clear it. This means that if you call populate_attributes, the same attributes that were dirty before the call will be dirty after the call (but no more and no less). This distinction is important because most subclasses of AbstractModel only save changed attributes, and ignore unchanged attributes. Attempting to change attributes through this method will cause them to not be saved, which is surely unexpected behaviour for most users.
Calling this method will also cause the model to assume that it is not a new record (see #new_record?).
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/virtualbox/abstract_model.rb', line 188 def populate_attributes(attribs, opts={}) ignore_dirty do super(attribs) populate_relationships(attribs) unless opts[:ignore_relationships] end # No longer a new record existing_record! end |