DDC-3859: Overriding default identifier generation strategy has no effect on associations #4726

Closed
opened 2026-01-22 14:48:23 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 31, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user bostaf:

Hello everyone,

I have an entity with custom ID generator strategy. It works flawlessly.
In some circumstances I have to override this strategy with a "handmade" Id. It works when the main entity is being flushed without associations. But it doesn't work with associations. This example error is thrown:
{quote}
An exception occurred while executing 'INSERT INTO articles_tags (article_id, tag_id) VALUES (?, ?)' with params ["a004r0", 4]:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (sf-test1.articles_tags, CONSTRAINT FK_354053617294869C FOREIGN KEY (article_id) REFERENCES article (id) ON DELETE CASCADE)
{quote}

This is when foreign keys are configured. For testing I deleted the foreign keys definitions manually. The result was no error, and the associated entity was saved with the foreign key generated based on the default generation strategy (loosing the actual associations). I posted more details on how to reproduce on StackOverflow: http://stackoverflow.com/q/31594338/709626.

I first found the issue using "pure" Doctrine 2.5.0. Then, while trying to debug, I reproduced it in Symfony 2.7.2.

Actually I'm not sure whether it's a bug or I am doing something not correctly. Also this is my first report here so please let me know if I should provide any more details.

Originally created by @doctrinebot on GitHub (Jul 31, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user bostaf: Hello everyone, I have an entity with custom ID generator strategy. It works flawlessly. In some circumstances I have to override this strategy with a "handmade" Id. It works when the main entity is being flushed without associations. But it doesn't work with associations. This example error is thrown: {quote} An exception occurred while executing 'INSERT INTO articles_tags (article_id, tag_id) VALUES (?, ?)' with params ["a004r0", 4]: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (sf-test1.articles_tags, CONSTRAINT FK_354053617294869C FOREIGN KEY (article_id) REFERENCES article (id) ON DELETE CASCADE) {quote} This is when foreign keys are configured. For testing I deleted the foreign keys definitions manually. The result was no error, and the associated entity was saved with the foreign key generated based on the default generation strategy (loosing the actual associations). I posted more details on how to reproduce on StackOverflow: http://stackoverflow.com/q/31594338/709626. I first found the issue using "pure" Doctrine 2.5.0. Then, while trying to debug, I reproduced it in Symfony 2.7.2. Actually I'm not sure whether it's a bug or I am doing something not correctly. Also this is my first report here so please let me know if I should provide any more details.
admin added the Bug label 2026-01-22 14:48:23 +01:00
admin closed this issue 2026-01-22 14:48:23 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 9, 2015):

Comment created by bostaf:

The report is invalid. I was only setting idGeneratorType

$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR*TYPE*NONE);

while I should also set idGenerator

$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());

Adding the other line has fixed the problem.

@doctrinebot commented on GitHub (Aug 9, 2015): Comment created by bostaf: The report is invalid. I was only setting `idGeneratorType` ``` $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR*TYPE*NONE); ``` while I should also set `idGenerator` ``` $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator()); ``` Adding the other line has fixed the problem.
Author
Owner

@doctrinebot commented on GitHub (Aug 9, 2015):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Aug 9, 2015): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4726