-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
Provided tests for testing if all references are set for crossreferences before saving
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4579,8 +4579,7 @@ public function add{$relatedObjectClassName}($crossObjectClassName $crossObjectN | |
} | ||
if (!\$this->" . $collName . "->contains(" . $crossObjectName . ")) { // only add it if the **same** object is not already associated | ||
\$this->doAdd{$relatedObjectClassName}($crossObjectName); | ||
\$this->" . $collName . "[]= " . $crossObjectName . "; | ||
\$this->" . $collName . "[] = " . $crossObjectName . "; | ||
} | ||
return \$this; | ||
|
@@ -4597,6 +4596,8 @@ protected function addCrossFKDoAdd(&$script, ForeignKey $refFK, ForeignKey $cros | |
{ | ||
$relatedObjectClassName = $this->getFKPhpNameAffix($crossFK, $plural = false); | ||
|
||
$selfRelationNamePlural = $this->getFKPhpNameAffix($refFK, $plural = true); | ||
|
||
$lowerRelatedObjectClassName = lcfirst($relatedObjectClassName); | ||
|
||
$joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); | ||
|
@@ -4615,6 +4616,12 @@ protected function doAdd{$relatedObjectClassName}(\${$lowerRelatedObjectClassNam | |
{$foreignObjectName} = new {$className}(); | ||
{$foreignObjectName}->set{$relatedObjectClassName}(\${$lowerRelatedObjectClassName}); | ||
\$this->add{$refKObjectClassName}({$foreignObjectName}); | ||
// set the back reference to this object directly as using provided method either results | ||
// in endless loop or in multiple relations | ||
if (!\${$lowerRelatedObjectClassName}->get{$selfRelationNamePlural}()->contains(\$this)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
marcj
Member
|
||
\$foreignCollection = \${$lowerRelatedObjectClassName}->get{$selfRelationNamePlural}(); | ||
\$foreignCollection[] = \$this; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Gamesh
Contributor
|
||
} | ||
} | ||
"; | ||
} | ||
|
This line of code uses up a lot of memory, by loading all related objects.
if you for example have a Book and Author, when you set and author on a book, all of authors books are loaded and checked if they are related. In my Case one author has about 1000 books, and if i do a batch add several authors to one book, then on each add for each author 1000 objects are loaded, by the second iteration you end up with 2000 objects and it quickly reaches memory limit