Skip to content

Commit

Permalink
Merge pull request #16 from jakejohns/hotfix/persist-many2many
Browse files Browse the repository at this point in the history
Fix Many-to-Many persistence
  • Loading branch information
pmjones authored Mar 31, 2021
2 parents e773d71 + 28de9e3 commit 2ef750a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Relationship/ManyToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,18 @@ public function persistForeign(Record $nativeRecord, SplObjectStorage $tracker)
$throughRecordSet = $nativeRecord->{$this->throughName};
$throughRecords = $throughRecordSet->getRecords();

foreach ($throughRecords as $throughRecord) {
// set for deletion, unless it matches
$throughRecord->setDelete(true);
}

// find foreigns with a matching through
foreach ($foreignRecordSet as $foreignRecord) {

// does the foreign match any through?
$matched = false;
foreach ($throughRecords as $i => $throughRecord) {

// set for deletion, unless it matches
$throughRecord->setDelete(true);

// does this through match the foreign?
if ($this->recordsMatch($throughRecord, $foreignRecord)) {
// matched
Expand Down

0 comments on commit 2ef750a

Please sign in to comment.