diff --git a/src/Relation.php b/src/Relation.php index a5adfc6..e31dc44 100644 --- a/src/Relation.php +++ b/src/Relation.php @@ -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; @@ -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(); + } } } diff --git a/tests/ManyTest.php b/tests/ManyTest.php index 73b5502..0fd939f 100644 --- a/tests/ManyTest.php +++ b/tests/ManyTest.php @@ -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() @@ -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() @@ -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() @@ -81,5 +84,6 @@ public function testFindAllManyStudents() $this->assertInstanceOf(Student::class, $students[1]); $this->assertSame('Elizabeth', $students[1]->firstname); + $this->assertFalse($students[0]->hasChanged()); } }