Model » Traits
Mondoc traits take your models to the next level by providing additional functionality.
Included traits from \District5\Mondoc\Db\Model\Traits\*
Mondoc includes several traits that can be used to enhance your models. These traits provide additional functionality to your models, automatic created and modified dates, and more. Below is a list of traits these traits, along with a brief description of each.
-
MondocCreatedDateTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocCreatedDateTrait
Adds a
cd
property to a model to utilise as a created date.This value is automatically assigned to the current UTC date upon initial save of a model, or if an existing model is updated and the
cd
property has not been set.You can override this behaviour by assigning a value to the
cd
property. -
MondocModifiedDateTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocModifiedDateTrait
Adds a
md
property to a model to utilise as a "last modified" date.This value is automatically assigned the current UTC date, but you can override this behaviour by assigning a value to the
md
property prior to saving. -
MondocVersionedModelTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocVersionedModelTrait
This trait introduces a
_v
property in the model, which you can choose to increment when you choose.You can detect if a model has a version by calling
isVersionableModel()
on the model. -
MondocRevisionNumberTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocRevisionNumberTrait
Adds an
_rn
property to a model to utilise as a revision number. This value is automatically set to1
upon initial save of a model, and is incremented each time the model is updated. You can override this behaviour by manually assigning a value to the_rn
property by callingsetRevisionNumber
method on your inheriting model. This is different from the versioned model trait, as the revision number is incremented each time the model is updated, regardless of the changes made.You can detect if a model has a revision number by calling
isRevisionNumberModel()
on the model. -
MondocCloneableTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocCloneableTrait
Adds a
clone
method to the model, which will return a new instance of the model with the same properties and values as the original.Optionally, when calling
$myModel->clone()
you can pass a boolean to indicate if you want to persist the new model to the database.-
$myModel->clone(true)
- The new model will be persisted to the database. -
$myModel->clone(false)
- The new model will not be persisted to the database.
The optional second parameter is the object or class you want to clone into. For example:
-
$newModel = $myModel->clone( < save:bool > )
- The$newModel
object will be the same type as$myModel
. -
$newModel = $myModel->clone( < save:bool > , OtherModel::class)
- The$newModel
object will be an instance ofOtherModel
.
-
-
MondocRetentionTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocRetentionTrait
The
MondocRetentionTrait
adds a retention policy to your model. This policy allows you to specify a time period for which the model data should be retained.Retained data is stored in a separate collection, and is not deleted from the original collection. This allows you to keep a record of data changes, and store them for a time specified by you.
The retention trait is more advanced than other traits. There is a dedicated page which documents the trait, and how to use it.
Please refer to the description Data retention section for more information.