Archived
1
0
Fork 0

app/library/Mvc/Model/Behavior/RandomId.php: add support for extending the expression used to find unique rows.

This commit is contained in:
Henrik Hautakoski 2018-06-11 23:56:09 +02:00
parent 58377273cc
commit fec9e5e656

View file

@ -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)
));