From 8b48ae8a93e8f21053043b145f74bb3173163754 Mon Sep 17 00:00:00 2001 From: michalsn Date: Tue, 7 Oct 2025 18:22:29 +0200 Subject: [PATCH] fix: unnecessary foreign key in Entity::$original --- src/Relation.php | 8 ++++++++ tests/ManyTest.php | 4 ++++ 2 files changed, 12 insertions(+) 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()); } }