Dan Rais
Dan Rais

Reputation: 319

Zend Framework - More than one record matches the supplied identity

Here is the problem. I have an eshop with users, they do not need to create account when ordering something, but they have a chance for it. I have a user that he first time refuse registering (I also save his data into User table with his email for order porpouses) but now he confirm and register account with new order he made. So what happens.. now he has two accounts in my db with same emails..(dont know why yet, it shouldnt). I have column in my db called active, if user is registered then active is 1. How can i tell ZendAuth to only choose this type of account?

Zend Error message now: More than one record matches the supplied identity.

My code:

     $db = Zend_Registry::get('db');
     $authAdapter = new Zend_Auth_Adapter_DbTable($db);
     $authAdapter->setTableName('user');
     $authAdapter->setCredentialColumn('password');
     $authAdapter->setIdentityColumn('email');
     $authAdapter->setCredential($password);
     $authAdapter->setIdentity($email);

I´am looking for something like $authAdapter->setContition('active = 1'); any suggestion?

Upvotes: 0

Views: 64

Answers (1)

Rob Ruchte
Rob Ruchte

Reputation: 3707

You can use the getDbSelect method of Zend_Auth_Adapter_DbTable to access the adapter's Zend_Db_Select instance and set your additional criteria on it. The docs show exactly your case in the last example.

// get the select object and set your additional where clause
$select = $authAdapter->getDbSelect();
$select->where('active = 1');

If possible you should consider adding a unique index for the email column.

Upvotes: 1

Related Questions