I have a validation problem. In Doctrine 1, I used this:
if ($model->isValid()) { $model->save(); } else { $errorStack = $model->getErrorStack(); ... }
and in $ errorStack I got the column name and error message. But in Doctrine 2, I can use just this:
An object
public function validate() { if ($this->name == null)) { throw new \Exception("Name can't be null"); } }
Controller:
try { $user = new \User(); //$user->setName('name'); $user->setCity('London'); $this->_entityManager->persist($user); $this->_entityManager->flush(); } catch(Exception $e) { error_log($e->getMessage()); }
but I have two problems:
- I do not know in which column?
- I do not want to check the unique manually
If I skip validate () from the entity, then unique (from this error.log) will be found
Unique violation: 7 ERROR: duplicate key value violates unique constraint "person_email_uniq"
but, for example, the user saves 2 records, and the first is erroneous, and the second is valid, after the first save, the EntityManager closes, and I canβt save the second (good) record because the "EntityManager is closed".
What is the best solution for this problem?
source share