zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

NoRecordExists and RecordExists does not work when exclude paramter is of cass Where #242

Closed Sebastian-Habiger closed 5 years ago

Sebastian-Habiger commented 5 years ago

As in line 300 of Zend\Validator\Db\AbstractDb the Where gets overridden the field to be checked gets lost. Changing this line to

$select
                        ->where
                        ->addPredicate($this->exclude);

will fix the issue. But should that Where not be inverted?

froschdesign commented 5 years ago

I think it was only intended for two parameter types; string and array. Compare with the DocBlock:

https://github.com/zendframework/zend-validator/blob/87e743d11d49a157011a49a962c25e7a11adc7c5/src/Db/AbstractDb.php#L179-L190

The problem is that the setExclude method does not validate the value of the parameter.

Sebastian-Habiger commented 5 years ago

Thank you, you are right, my fault. I was sure I read somewhere in the documentation that a where is allowed. Using a string instead of a Where is the solution.