Identity through foreign Entities - persist #5261

Closed
opened 2026-01-22 15:02:53 +01:00 by admin · 0 comments
Owner

Originally created by @Gorjunov on GitHub (Sep 19, 2016).

Originally assigned to: @lcobucci on GitHub.

I try to implement schema from http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity (OneToOne relation between models and second model's primary key is also foreign key to first model)

When I try to create both entities at same time and persist them ($entityManager->persist($address)) I get Doctrine\ORM\ORMInvalidArgumentException: The given entity of type ‘Address' (Address@0000000055b6ca6a000000001effbba7) has no identity/no id values set. It cannot be added to the identity map

Is there any solution (except saving User, adding it to address and then saving address) to realize it.

P.S.
I've tried to change Doctrine\ORM\Id\AssignedGenerator by adding:

    public function isPostInsertGenerator()
    {
        return true;
    }

This change has fixed my problem, but I'm afraid, that AssignedGenerator change is bad idea.

Originally created by @Gorjunov on GitHub (Sep 19, 2016). Originally assigned to: @lcobucci on GitHub. I try to implement schema from http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity (OneToOne relation between models and second model's primary key is also foreign key to first model) When I try to create both entities at same time and persist them (`$entityManager->persist($address)`) I get `Doctrine\ORM\ORMInvalidArgumentException: The given entity of type ‘Address' (Address@0000000055b6ca6a000000001effbba7) has no identity/no id values set. It cannot be added to the identity map` Is there any solution (except saving User, adding it to address and then saving address) to realize it. P.S. I've tried to change `Doctrine\ORM\Id\AssignedGenerator` by adding: ``` public function isPostInsertGenerator() { return true; } ``` This change has fixed my problem, but I'm afraid, that AssignedGenerator change is bad idea.
admin added the Bug label 2026-01-22 15:02:53 +01:00
admin closed this issue 2026-01-22 15:02:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5261