Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/18f1290b429fd4a8ec35 to your computer and use it in GitHub Desktop.
Save doctrinebot/18f1290b429fd4a8ec35 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-875 - https://github.com/doctrine/doctrine2/issues/5398
diff --git "a/C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\UnitOfWork_HEAD.php" "b/D:\\Projects\\ORM\\doctrine2\\lib\\Doctrine\\ORM\\UnitOfWork.php"
index 5088bb2..f39e511 100644
--- "a/C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\UnitOfWork_HEAD.php"
+++ "b/D:\\Projects\\ORM\\doctrine2\\lib\\Doctrine\\ORM\\UnitOfWork.php"
@@ -1465,7 +1465,11 @@ class UnitOfWork implements PropertyChangedListener
if ($assoc['type'] & ClassMetadata::TO_ONE) {
$prevClass->reflFields[$assocField]->setValue($prevManagedCopy, $managedCopy);
} else {
- $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy);
+ //$prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy);
+ $arrayCollection = $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->unwrap();
+ if (!$arrayCollection->contains($managedCopy))
+ $arrayCollection->add($managedCopy);
+
if ($assoc['type'] == ClassMetadata::ONE_TO_MANY) {
$class->reflFields[$assoc['mappedBy']]->setValue($managedCopy, $prevManagedCopy);
}
f8e2a546ad895b2cfd936dfd1032b6c732e1a1f8
lib/Doctrine/ORM/UnitOfWork.php | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php
index d3101b3..dd42ee8 100644
--- a/lib/Doctrine/ORM/UnitOfWork.php
+++ b/lib/Doctrine/ORM/UnitOfWork.php
@@ -1466,9 +1466,8 @@ class UnitOfWork implements PropertyChangedListener
$prevClass->reflFields[$assocField]->setValue($prevManagedCopy, $managedCopy);
} else {
// Only add to the collection if the entity doesn't already exist in it
- $arrayCollection = $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->unwrap();
- if (!$arrayCollection->contains($managedCopy))
- $arrayCollection->add($managedCopy);
+ if (!$prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->unwrap()->contains($managedCopy))
+ $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy);
if ($assoc['type'] == ClassMetadata::ONE_TO_MANY) {
$class->reflFields[$assoc['mappedBy']]->setValue($managedCopy, $prevManagedCopy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment