Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1.14 KB

03_hashable.md

File metadata and controls

46 lines (36 loc) · 1.14 KB

Hashable

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.

Configuration

array(
    'Model\Article' => array(
        'fields' => array(
            'title' => 'string',
            'content' => 'string'
        ),
        'behaviors' => array(
            array(
                'class' => 'Mongator\Behavior\Hashable'
                'fromFields' => array(
                    'title'
                )
            )
        ),
    ),
);

Options

  • createdEnabled (default true): whether the hash will be saved when the documents are created
  • updatedEnabled (default true): whether the hash will be saved when the documents are updated
  • field (default 'hash'): field used to store the hash
  • fromFields (default array()): the list of fields used to create the hash. If empty, all fields will be used.

Usage

$article = $mongator->create('Model\Article')->setTitle('Mongator')->save();

echo $article->getHash(); // 4b8c729a6052a92c6e0bce7b6f119e63