R
R
Roquefort2017-07-05 11:13:06
Doctrine ORM
Roquefort, 2017-07-05 11:13:06

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();

how to add a select type to a transaction
SELECT MAX(number) as number FROM contracts
Make an increment of the result obtained and all this is just flashing.
The number fields are not unique. AUTO field increment will not work because one contract can occupy several lines in the database with the same number. The reason that everything is needed in one transaction is that when two or three people create contracts at the same time, the contracts do not have the same number

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
novrm, 2017-07-05
@novrm

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 question

Ask a Question

731 491 924 answers to any question