mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
Fixes #16022: Fix UniqueValidator for PostgreSQL. Checks the uniqueness of keys in jsonb field
This commit is contained in:
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
||||
2.0.16 under development
|
||||
------------------------
|
||||
|
||||
- Bug #16022: Fix UniqueValidator for PostgreSQL. Checks the uniqueness of keys in `jsonb` field (lav45)
|
||||
- Bug #16903: Fixed 'yii\validators\NumberValidator' method 'isNotNumber' returns false for true/false value (annechko)
|
||||
- Bug #16648: Html::strtolower() was corrupting UTF-8 strings (Kolyunya)
|
||||
- Bug #13977: Skip validation if file input does not exist (RobinKamps, s1lver)
|
||||
|
||||
@ -178,7 +178,7 @@ class UniqueValidator extends Validator
|
||||
*/
|
||||
private function modelExists($targetClass, $conditions, $model)
|
||||
{
|
||||
/** @var ActiveRecordInterface $targetClass $query */
|
||||
/** @var ActiveRecordInterface|\yii\base\BaseObject $targetClass $query */
|
||||
$query = $this->prepareQuery($targetClass, $conditions);
|
||||
|
||||
if (!$model instanceof ActiveRecordInterface || $model->getIsNewRecord() || $model->className() !== $targetClass::className()) {
|
||||
@ -311,10 +311,12 @@ class UniqueValidator extends Validator
|
||||
$prefixedConditions = [];
|
||||
foreach ($conditions as $columnName => $columnValue) {
|
||||
if (strpos($columnName, '(') === false) {
|
||||
$prefixedColumn = "{$alias}.[[" . preg_replace(
|
||||
'/^' . preg_quote($alias) . '\.(.*)$/',
|
||||
'$1',
|
||||
$columnName) . ']]';
|
||||
$columnName = preg_replace('/^' . preg_quote($alias) . '\.(.*)$/', '$1', $columnName);
|
||||
if (strpos($columnName, '[[') === 0) {
|
||||
$prefixedColumn = "{$alias}.{$columnName}";
|
||||
} else {
|
||||
$prefixedColumn = "{$alias}.[[{$columnName}]]";
|
||||
}
|
||||
} else {
|
||||
// there is an expression, can't prefix it reliably
|
||||
$prefixedColumn = $columnName;
|
||||
|
||||
Reference in New Issue
Block a user