app/library/Mvc/Model/Behavior/RandomId.php: add support for extending the expression used to find unique rows.
This commit is contained in:
parent
58377273cc
commit
fec9e5e656
1 changed files with 7 additions and 1 deletions
|
|
@ -60,6 +60,12 @@ class RandomId extends Behavior implements BehaviorInterface
|
|||
$field = $this->_options['field'];
|
||||
$len = $this->_options['length'];
|
||||
|
||||
if (isset($this->_options['expression'])) {
|
||||
$expr = 'AND ' . $this->_options['expression'];
|
||||
} else {
|
||||
$expr = '';
|
||||
}
|
||||
|
||||
if ($model->$field === null) {
|
||||
|
||||
$random = new \Phalcon\Security\Random();
|
||||
|
|
@ -67,7 +73,7 @@ class RandomId extends Behavior implements BehaviorInterface
|
|||
$id = substr($random->base64Safe(), 0, $len);
|
||||
|
||||
$count = $model->count(array(
|
||||
"$field = ?0",
|
||||
"$field = ?0 $expr",
|
||||
'bind' => array($id)
|
||||
));
|
||||
|
||||
|
|
|
|||
Reference in a new issue