I have following table (type, id, title).
When new object is created and type=1 id should be 1, next object with type=1 id=2… But when I create object with type=2 id should be 1.
How can I do it with Doctrine2 and Symfony2?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Like other have said, Doctrine 2 does not do this out of the box. The common practice is to make the ID field auto increment and a primary key in which case this is not possible. Primary keys must be unique.
With that said, a solution could be to use the entity manage to find the maximum value of ID where the type is the selected type and incrementing that value by 1.
For example: