zendframework/zend-validator

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

Closed this issue · 2 comments

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?

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

/**
* Sets a new exclude clause
*
* @param string|array $exclude
* @return self Provides a fluent interface
*/
public function setExclude($exclude)
{
$this->exclude = $exclude;
$this->select = null;
return $this;
}

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

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.