Skip to content

Commit 8b48ae8

Browse files
committed
fix: unnecessary foreign key in Entity::$original
1 parent cf01743 commit 8b48ae8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Relation.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ public function filterResult(array|Entity $row, string $returnType): array|Entit
270270
unset($row[$this->many->pivotForeignKey]);
271271
} else {
272272
unset($row->{$this->many->pivotForeignKey});
273+
274+
if ($row instanceof Entity) {
275+
$row->syncOriginal();
276+
}
273277
}
274278

275279
return $row;
@@ -286,6 +290,10 @@ public function filterResults(array|Entity $results, string $returnType): array|
286290
unset($row[$this->many->pivotForeignKey]);
287291
} else {
288292
unset($row->{$this->many->pivotForeignKey});
293+
294+
if ($row instanceof Entity) {
295+
$row->syncOriginal();
296+
}
289297
}
290298
}
291299

tests/ManyTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function testFindManyCourses()
3737

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

4243
public function testFindAllManyCourses()
@@ -51,6 +52,7 @@ public function testFindAllManyCourses()
5152

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

5658
public function testFindManyStudents()
@@ -67,6 +69,7 @@ public function testFindManyStudents()
6769

6870
$this->assertInstanceOf(Student::class, $students[0]);
6971
$this->assertSame('Joe', $students[0]->firstname);
72+
$this->assertFalse($students[0]->hasChanged());
7073
}
7174

7275
public function testFindAllManyStudents()
@@ -81,5 +84,6 @@ public function testFindAllManyStudents()
8184

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

0 commit comments

Comments
 (0)