Module DataMapper::Persistence::ConvenienceMethods::InstanceMethods
In: lib/data_mapper/persistence.rb
lib/data_mapper/persistence.rb

Methods

destroy!   destroy!   reload   reload   reload!   reload!   save   save   save!   save!  

Public Instance methods

Deletes the model from the database and de-activates associations

[Source]

     # File lib/data_mapper/persistence.rb, line 184
184:         def destroy!
185:           database_context.destroy(self)
186:         end

Deletes the model from the database and de-activates associations

[Source]

     # File lib/data_mapper/persistence.rb, line 184
184:         def destroy!
185:           database_context.destroy(self)
186:         end
reload(cols = nil)

Alias for reload!

reload(cols = nil)

Alias for reload!

Reloads a model‘s properties from the database. This also includes data for any associated models that have been loaded from the database.

You can limit the properties being reloaded by passing in an array of symbols.

[Source]

     # File lib/data_mapper/persistence.rb, line 176
176:         def reload!(cols = nil)
177:           database_context.first(self.class, key, :select => ([self.class.table.key.to_sym] + (cols || original_values.keys)).uniq, :reload => true)
178:           self.loaded_associations.each { |association| association.reload! }
179:           self
180:         end

Reloads a model‘s properties from the database. This also includes data for any associated models that have been loaded from the database.

You can limit the properties being reloaded by passing in an array of symbols.

[Source]

     # File lib/data_mapper/persistence.rb, line 176
176:         def reload!(cols = nil)
177:           database_context.first(self.class, key, :select => ([self.class.table.key.to_sym] + (cols || original_values.keys)).uniq, :reload => true)
178:           self.loaded_associations.each { |association| association.reload! }
179:           self
180:         end

Save updated properties to the database.

Returns

 True::  successfully saved the object to the database
 False:: an error occured when saving the object to the database.
         check valid? to see if validation error occured

@public

[Source]

     # File lib/data_mapper/persistence.rb, line 150
150:         def save
151:           database_context.save(self)
152:         end

Save updated properties to the database.

Returns

 True::  successfully saved the object to the database
 False:: an error occured when saving the object to the database.
         check valid? to see if validation error occured

@public

[Source]

     # File lib/data_mapper/persistence.rb, line 150
150:         def save
151:           database_context.save(self)
152:         end

This behaves in the same way as save, but raises a ValidationError if the model is invalid. Successful saves return true.

Returns

 True:: successfully saved the object to the database

Raises

 ValidationError::
    The object could not be saved to the database due to validation
    errors

@public

[Source]

     # File lib/data_mapper/persistence.rb, line 165
165:         def save!
166:           raise ValidationError.new(errors) unless save
167:           return true
168:         end

This behaves in the same way as save, but raises a ValidationError if the model is invalid. Successful saves return true.

Returns

 True:: successfully saved the object to the database

Raises

 ValidationError::
    The object could not be saved to the database due to validation
    errors

@public

[Source]

     # File lib/data_mapper/persistence.rb, line 165
165:         def save!
166:           raise ValidationError.new(errors) unless save
167:           return true
168:         end

[Validate]