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
cdproperty 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
cdproperty has not been set.You can override this behaviour by assigning a value to the
cdproperty. -
MondocModifiedDateTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocModifiedDateTrait
Adds a
mdproperty 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
mdproperty prior to saving. -
MondocVersionedModelTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocVersionedModelTrait
This trait introduces a
_vproperty 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
_rnproperty to a model to utilise as a revision number. This value is automatically set to1upon 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_rnproperty by callingsetRevisionNumbermethod 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
clonemethod 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$newModelobject will be the same type as$myModel. -
$newModel = $myModel->clone( < save:bool > , OtherModel::class)- The$newModelobject will be an instance ofOtherModel.
-
-
MondocRetentionTrait
Full namespace: \District5\Mondoc\Db\Model\Traits\MondocRetentionTrait
The
MondocRetentionTraitadds 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.