Hi i have just updated to the latest version d811f1e
and now my exists validator fails with an sql error.
I have this rule in my Submission Class.
[['submission_call_id'], 'exist', 'skipOnError' => true, 'targetClass' => SubmissionCall::className(), 'targetAttribute' => ['submission_call_id' => 'id']],
The SubmissionCall Class have this tablename
public static function tableName()
{
return '{{%submission_call}}';
}
The generated sql is
SELECT EXISTS(SELECT * FROM `submission_call` WHERE (`0`.`id`='12'))`
Of course this sql is wrong, but why?
Are there still some changes to the exists validator missing?
Is this a newly introduced bug due to the latest change?
| Q | A
| ---------------- | ---
| Yii version | d811f1e
| PHP version | 5.6
| Operating system | Windows
Is this a newly introduced bug due to the latest change?
quite sure it is.
rules like this
[['unitId'], 'exist',
'skipOnError' => true,
'targetClass' => DurationUnit::className(),
'targetAttribute' => ['unitId' => DurationUnit::tableName() . '.id'],
'filter' => function (DurationUnitQuery $query) {
$query->active();
}
],
produced error now :rage: :anger: :fire: :fire_engine:
SELECT EXISTS(SELECT * FROM `duration_unit` WHERE (`duration_unit`.[[`duration_unit`.id]]=1) AND (`duration_unit`.`stateOfFlags`=1))'
:smile_cat:
Can create "error on exists validator after c6ab3f8" :1st_place_medal:
So... Tell about usages getTablesUsedInFrom - how many places we need changes?
Ohh... the case for manual prefixing wasn't taken into account :(
https://github.com/yiisoft/yii2/blob/master/framework/validators/ExistValidator.php#L226
https://github.com/yiisoft/yii2/blob/master/framework/validators/UniqueValidator.php#L179
https://github.com/yiisoft/yii2/blob/master/framework/validators/UniqueValidator.php#L299
I think need function named like applyPrefix($column, $prefix = null) for this case
Yes. Something like that. I'm temporary busy. If you want to work on it in few next days, feel free to do so.
So... Ordinary unique validator has some error without alias :smile_cat:
[['unitId', 'value'], 'unique', 'targetAttribute' => ['unitId', 'value']],
SELECT EXISTS(SELECT * FROM `duration` WHERE (`duration`.[[{unitId}]]=1) AND (`duration`.[[{value}]]=1))'
md5-c81f2c3c8b7dc33744aee7c3fc7515c3
{{%duration}}.[[unitId]]
{{%duration}}.[[value]]
@Bhoft could you try now?
Works. The select for the exists validation is now correct:
SELECT EXISTS(SELECT * FROM `submission_call` WHERE (`submission_call`.`id`=12))