Yii2: UniqueValidator breaking for non-SQL ActiveRecord

Created on 1 Feb 2017  路  17Comments  路  Source: yiisoft/yii2

All 17 comments

This line was compatible with the interfaces before, but now requires a specific implementation:

https://github.com/yiisoft/yii2/blob/72a690216a7165be1402271db353199044218d7f/framework/validators/UniqueValidator.php#L163

cc @developeruz

We should add an instanceof check there.

ActiveQueryInterface::asArray() should be used at that line instead of createCommand() usage.

select() is also not provided by some implementations such as redis.

@klimov-paul asArray() does not prevent afterFind(). See https://github.com/yiisoft/yii2/issues/13453

@samdark afterFind() is not called on an array...

Right.

select() can be avoided at all

it was added for optimization.

I have noticed

Still, either it should belong QueryInterface or removed from validator.

check for $query instanceof \yii\db\ActiveQuery can be done. I am working on a solution.

$query always instanceof ActiveQuery or not?

@developeruz nope https://github.com/yiisoft/yii2-mongodb/blob/master/ActiveQuery.php

That's active query but not DB active query.

@developeruz no, it can be an instance of mongodb, elasticsearch or redis query. the only thing they have in common is ActiveQueryInterface.

The fix looks good to me.

It is good but it is not enough. I am working on tests for redis and elasticsearch.

@developeruz I have included your fix in #13487. Thank you!

Was this page helpful?
0 / 5 - 0 ratings