Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Validator\Db\NoRecordExists with Select needs first where clause as the given field #97

Open
GeeH opened this issue Jun 28, 2016 · 1 comment

Comments

@GeeH
Copy link

GeeH commented Jun 28, 2016

This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7602
User: @YuriStruszczynski
Created On: 2015-07-02T09:18:48Z
Updated At: 2015-11-06T22:06:43Z
Body
//Check that the emailaddress for a given project is not present in the database
$select = new \Zend\Db\Sql\Select();
$select->columns(array('mail'))->from('candidates')->where(array('mail' => '', 'project_id' => $id));
$validator = new \Zend\Validator\Db\NoRecordExists($select);
$dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
$validator->setAdapter($dbAdapter);
$inputFilter->get('mail')->getValidatorChain()->attach($validator);

This one works fine! But if you change to the next line, the fields will not be validated:
$select->columns(array('mail'))->from('candidates')->where(array('project_id' => $id, 'mail' => ''));

Because in AbstractDb.php the query() function overrides your first where parameter with the value of the connected field:
$parameters = $statement->getParameterContainer();
$parameters['where1'] = $value;

In my opinion this should be mentioned somewhere or be changed like this:

if ($this->select instanceof Select) {
$parameters = $statement->getParameterContainer();
$parameters['where1'] = $value;
}


@michalbundyra
Copy link
Member

This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at laminas/laminas-validator#37.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants