Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ public function filterResult(array|Entity $row, string $returnType): array|Entit
unset($row[$this->many->pivotForeignKey]);
} else {
unset($row->{$this->many->pivotForeignKey});

if ($row instanceof Entity) {
$row->syncOriginal();
}
}

return $row;
Expand All @@ -286,6 +290,10 @@ public function filterResults(array|Entity $results, string $returnType): array|
unset($row[$this->many->pivotForeignKey]);
} else {
unset($row->{$this->many->pivotForeignKey});

if ($row instanceof Entity) {
$row->syncOriginal();
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/ManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testFindManyCourses()

$this->assertInstanceOf(Course::class, $courses[0]);
$this->assertSame('Baking for dummies', $courses[0]->name);
$this->assertFalse($courses[0]->hasChanged());
}

public function testFindAllManyCourses()
Expand All @@ -51,6 +52,7 @@ public function testFindAllManyCourses()

$this->assertInstanceOf(Course::class, $courses[0]);
$this->assertSame('PHP is not death', $courses[0]->name);
$this->assertFalse($courses[0]->hasChanged());
}

public function testFindManyStudents()
Expand All @@ -67,6 +69,7 @@ public function testFindManyStudents()

$this->assertInstanceOf(Student::class, $students[0]);
$this->assertSame('Joe', $students[0]->firstname);
$this->assertFalse($students[0]->hasChanged());
}

public function testFindAllManyStudents()
Expand All @@ -81,5 +84,6 @@ public function testFindAllManyStudents()

$this->assertInstanceOf(Student::class, $students[1]);
$this->assertSame('Elizabeth', $students[1]->firstname);
$this->assertFalse($students[0]->hasChanged());
}
}