The Hashable behavior automatically saves a hash string based on all or some of the document's fields.
Works with all type of fields, relations or embedded documents.
array(
'Model\Article' => array(
'fields' => array(
'title' => 'string',
'content' => 'string'
),
'behaviors' => array(
array(
'class' => 'Mongator\Behavior\Hashable'
'fromFields' => array(
'title'
)
)
),
),
);
createdEnabled
(default true): whether the hash will be saved when the documents are createdupdatedEnabled
(default true): whether the hash will be saved when the documents are updatedfield
(default 'hash'): field used to store the hashfromFields
(default array()): the list of fields used to create the hash. If empty, all fields will be used.
$article = $mongator->create('Model\Article')->setTitle('Mongator')->save();
echo $article->getHash(); // 4b8c729a6052a92c6e0bce7b6f119e63