The Archivable behavior makes a copy of a document in an other collection, on-demand or when the document is created/updated/deleted
array(
'Model\Article' => array(
'fields' => array(
'title' => 'string',
),
'behaviors' => array(
array(
'class' => 'Mongator\Behavior\Archivable',
),
),
),
);
archive_class
(default '%class%\Archive'): the new model used to make the copiescollection_class
(default '%collection%Archive'): the collection where the copies will be storedid_field
(default 'document'): the field of the copy where the original id will be savedarchived_at_field
(default 'archived_at_field'): the field of the original document where the archived id will be savedarchive_on_insert
(default false): create a copy of the document when it is createdarchive_on_update
(default false): create a copy of the document when it is updatedarchive_on_delete
(default true): create a copy of the document when it is deletedfields
(default array()): the list of fields used to create the copy. If empty, all fields will be used
$article = $this->mongator->create('Model\Article')
->setTitle('foo')
->save();
$id = $article->getId();
$article->delete();
$copy = $this->mongator
->getRepository('Model\Article\Archive')
->createQuery(array('document' => $id))
->one();
echo $copy->getTitle(); // foo