module

Marten::DB::Model::Persistence

Instance methods

delete(using : Nil | String | Symbol = nil)

Deletes the model instance.

This methods deletes the model instance by complying to the deletion rules defined as part of the relation fields if applicable (on_delete option on many to one or one to one fields). It returns the number of rows that were deleted as part of the record deletion.

Source
deleted?

Returns a boolean indicating if the record was deleted or not.

This method returns true if the model instance was deleted previously. Otherwise it returns false in any other cases.

Source
new_record?

Returns a boolean indicating if the record doesn't exist in the database yet.

This methods returns true if the model instance hasn't been saved and doesn't exist in the database yet. In any other cases it returns false.

Source
persisted?

Returns a boolean indicating if the record is persisted in the database.

This method returns true if the record at hand exists in the database. Otherwise (if it's a new record or if it was deleted previously), the method returns false.

Source
reload

Reloads the model instance.

This methods retrieves the record at the database level and updates the current model instance with the new values.

Source
save(using : Nil | String | Symbol = nil, validate : Bool = true) : Bool

Saves the model instance.

If the model instance is new, a new record is created in the DB ; otherwise the existing record is updated. This method will return true if the model instance is valid and was created / updated successfully. Otherwise it will return false if the model instance validation failed.

Source
save!(using : Nil | String | Symbol = nil, validate : Bool = true) : Bool

Saves the model instance.

If the model instance is new, a new record is created in the DB ; otherwise the existing record is updated. This method will return true if the model instance is valid and was created / updated successfully. Otherwise it will raise a Marten::DB::Errors::InvalidRecord exception if the model instance validation failed.

Source
update(values : Hash | NamedTuple)

Updates the model instance.

This method updates the passed field values and then saves the record. This method returns true if the model instance is valid and was created / updated successfully. Otherwise it returns false if the model instance validation fails.

Source
update

Updates the model instance.

This method updates the passed field values and then saves the record. This method returns true if the model instance is valid and was created / updated successfully. Otherwise it returns false if the model instance validation fails.

Source
update!(values : Hash | NamedTuple)

Updates the model instance.

This method updates the passed field values and then saves the record. This method returns true if the model instance is valid and was created / updated successfully. Otherwise it raises a Marten::DB::Errors::InvalidRecord exception if the model instance validation fails.

Source
update!

Updates the model instance.

This method updates the passed field values and then saves the record. This method returns true if the model instance is valid and was created / updated successfully. Otherwise it raises a Marten::DB::Errors::InvalidRecord exception if the model instance validation fails.

Source

Nested types