Answer the question
In order to leave comments, you need to log in
How to write number auto-generation in Doctrina?
I need to write a number auto-generation. I'm using doctrine to create an entry.
$contract = new Contracts();
$contract->exchangeArray($form->getData());
$contract->setContactId($contactId);
$contract->setType($type);
$contract->setCreatedAt($date);
$this->getEntityManager()->persist($contract);
$this->getEntityManager()->flush();
SELECT MAX(number) as number FROM contracts
Answer the question
In order to leave comments, you need to log in
If you are working with Doctrine, you must have a unique INT id for each entry.
And since there is a unique id, you can auto-increment it. This is the standard solution for your problem.
Dancing with a tambourine is superfluous and harmful.
For...
If you carefully read the manual for Doctirne, you will not step on the rake of a beginner who takes any field for a unique one. Any is impossible.
28.1.1. Join-Columns with non-primary keys
It is not possible to use join columns pointing to non-primary keys. Doctrine will think these are the primary keys and create lazy-loading proxies with the data, which can lead to unexpected results. Doctrine can for performance reasons not validate the correctness of this settings at runtime but only through the Validate Schema command.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question