zendframework / zend-validator

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

AbstractDb - Exclude Parameter - Bug #69

Open h3christophe opened 8 years ago

h3christophe commented 8 years ago

Abstract Class Zend\Validator\Db\AbstractDb;

The function getSelect has a bug when you the exclude parameter contains a Zend\Db\Sql\Where parameter

if ($this->exclude !== null) {
            if (is_array($this->exclude)) {
                $select->where->notEqualTo(
                    $this->exclude['field'],
                    $this->exclude['value']
                );
            } else {
-->>>                $select->where($this->exclude);
            }
        }

The problem is that $select->where($this->exclude) will overwrite the entire WHERE clause defined just above

$select          = new Select();
        $tableIdentifier = new TableIdentifier($this->table, $this->schema);
        $select->from($tableIdentifier)->columns([$this->field]);
        $select->where->equalTo($this->field, null);

The workaround is when you pass a WHERE inside the exclude you have to repeat

equalTo($this->field, null);

The fix would be to use

if($this->exclude instanceof Where){
 $select->where->addPredicate($this->exclude);
} else {
 $select->where($this->exclude);
}

Thank you

michalbundyra commented 4 years ago

This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at https://github.com/laminas/laminas-validator/issues/41.