2012-04-05

I am using Doctrine 2.2.1 and CodeIgniter 2.1.0

I am attempting to do unique validation on an email address field from a form - simply to make sure that the field does not already exist in the database.

I started by checking this good (but outdated) tutorial here and the CodeIgniter documentation here

The CI documentation shows examples using is_unique[table.field] and also seems to say that using a callback can do this but I don't seem to be grasping how that code does it, and I cannot make it work myself.

I have tried this:

and this:

(which is cribbed almost verbatim from the CodeIgniter example)

Neither work. The first gives me the following output:

The second gives me this output:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'email@address.com' for key 'email_index'' in /../applicationFolder/libraries/Doctrine/DBAL/Statement.php:131 Stack trace: #0 /../applicationFolder/libraries/Doctrine/DBAL/Statement.php(131): PDOStatement->execute(NULL) #1 /../applicationFolder/libraries/Doctrine/ORM/Persisters/BasicEntityPersister.php(239): Doctrine\DBAL\Statement->execute() #2 /../applicationFolder/libraries/Doctrine/ORM/UnitOfWork.php(896): Doctrine\ORM\Persisters\BasicEntityPersister->executeInserts() #3 /../applicationFolder/libraries/Doctrine/ORM/UnitOfWork.php(304): Doctrine\ORM\UnitOfWork->executeInserts(Object(Doctrine\ORM\Mapping\ClassMetadata in /../applicationFolder/libraries/Doctrine/DBAL/Statement.php on line 131

Am I overlooking something simple? Any help with how to correctly do a unique validation against the DB with CI/Doctrine? Thanks!

Note: I was able to get $this->form_validation->set_rules('email', 'E-mail', 'required|valid_email|is_unique[users.email]'); working after adding 'database' to the autoload config, however, this breaks Doctrine entirely.

Show more