mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-922: Persisting an entity with an 1:n collection of related entites fails if the FK ist part of a composite PK #1147
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Dec 9, 2010).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user branleb:
If you got two Entities A and B where A is a sample Entity with a 1:n relation to the Entity B
and B has a composite PK with the FK (A id) and a custom field like this:
If you try to persist an object of A holding one or more references to objects of B, the objects get correctly persistet. This means, that every inserted record of B has a correctly filled field "entity_a_id". The objects of B also have a correct reference to A holding now the new A record with its autoinc id.
But the object property "entity_a_id" stays empty. This leads to a collection of unusable EntityB objects (in memory), since on another persist of EntityA the values of entity_a_id are still not set correctly but the state is managed which leads to an "update B ... where entity_a_id=0"
We've tried to set the entity_a_id with an event handler on postPersist. On a persist of EntityA the collection entities wanted to update their entity_a_ids from 0 to the correct one.
@doctrinebot commented on GitHub (Dec 10, 2010):
Comment created by @beberlei:
Fixed formating
@doctrinebot commented on GitHub (Dec 10, 2010):
Comment created by @beberlei:
When dealing with foreign keys as composite keys you are currently forced to make use of the "Assigned Id Generator".
This means you have to make sure the IDs are set to their values before calling ->persist().
@doctrinebot commented on GitHub (Dec 10, 2010):
Comment created by @beberlei:
This issue will be fixed when DDC-117 is merged into master. That will happen for the 2.1 release.
@doctrinebot commented on GitHub (Jan 2, 2011):
Comment created by @beberlei:
Implemented
@doctrinebot commented on GitHub (Jan 2, 2011):
Issue was closed with resolution "Fixed"