-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DDC-3378] Support merging entities with composite identities defined through to-one associations #1176
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-3378 We use Jira to track the state of pull requests and the versions they got |
@adrienbrault there is a class naming collision in the test case. |
5d5fc67
to
e17a180
Compare
$state->country = $country; | ||
|
||
$this->_em->merge($country); | ||
$this->_em->merge($state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the following works:
$country = new MergeCompositeToOneKeyCountry();
$country->country = 'US';
$state = new MergeCompositeToOneKeyState();
$state->state = 'CA';
$state->country = $country;
$newCountry = $this->_em->merge($country);
$state->country = $newCountry;
$this->_em->merge($state);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, merge() does not make the argument it receives managed. It returns a new instance which is managed (because it might already have it in its identity map).
So you issue is a wrong usage of merge()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that Doctrine can be configured to cascade the merge operation, which could help you in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof I've updated the test to a valid use case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that the cascading merges happens after uow tries to get the State id, and at that point the Country is not managed
@Ocramius Updated |
@@ -59,12 +59,8 @@ public function generate(EntityManager $em, $entity) | |||
} | |||
|
|||
if (isset($class->associationMappings[$idField])) { | |||
if ( ! $em->getUnitOfWork()->isInIdentityMap($value)) { | |||
throw ORMException::entityMissingForeignAssignedId($entity, $value); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing this check looks wrong to me. It is expected to enforce using managed entities
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue when you remove this is that you now allow using unmanaged entities in identifiers even in contexts where it should not be allowed. Fixing the retrieval of the id when merging should not be done by opening all other cases for bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is actually correct though - identities deriving from associations are still valid, even for un-managed entities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, indeed. The relation itslef will still be required to use a managed entity in other places
I can reproduce this with the following use case:
The merge code tries to flatten a composite key with a foreign identifier but requires the entity identifier values that were just cleared. |
@hjr3 does this apply also to the codebase after @adrienbrault's patch? |
@Ocramius the patch from @adrienbrault does address my issue. |
@adrienbrault can you check @stof's comment please? |
@adrienbrault merged, thanks!
|
I hope that I'm doing something wrong and that this is not a bug ...