From e2ca3e906142abb1dade60ee5efb4425f5e708b2 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Mon, 21 Aug 2023 15:46:05 +0100 Subject: [PATCH] FIX: Stop ManyManyThroughList join records incorrectly showing as changed (fixes #10821) --- src/ORM/ManyManyThroughList.php | 2 +- tests/php/ORM/ManyManyThroughListTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ORM/ManyManyThroughList.php b/src/ORM/ManyManyThroughList.php index 6bd5050a030..1d8ce4923f3 100644 --- a/src/ORM/ManyManyThroughList.php +++ b/src/ORM/ManyManyThroughList.php @@ -87,7 +87,7 @@ public function createDataObject($row) if ($joinRow) { $joinClass = $this->manipulator->getJoinClass(); $joinQueryParams = $this->manipulator->extractInheritableQueryParameters($this->dataQuery); - $joinRecord = Injector::inst()->create($joinClass, $joinRow, false, $joinQueryParams); + $joinRecord = Injector::inst()->create($joinClass, $joinRow, DataObject::CREATE_HYDRATED, $joinQueryParams); $record->setJoin($joinRecord, $joinAlias); } diff --git a/tests/php/ORM/ManyManyThroughListTest.php b/tests/php/ORM/ManyManyThroughListTest.php index 26211d7c207..acb2bb4ccb4 100644 --- a/tests/php/ORM/ManyManyThroughListTest.php +++ b/tests/php/ORM/ManyManyThroughListTest.php @@ -514,4 +514,19 @@ public function testRemoveCallbackOnRemoveAll() $relation->removeAll(); $this->assertEquals(sort($remove), sort($removedIds)); } + + public function testChangedFields() + { + /** @var ManyManyThroughListTest\TestObject $parent */ + $parent = $this->objFromFixture(ManyManyThroughListTest\TestObject::class, 'parent1'); + $item1 = $parent->Items()->first(); + + // Nothing has changed yet + $this->assertEmpty($item1->getChangedFields()); + $this->assertFalse($item1->isChanged('Title')); + + // Change a field, ensure change is flagged + $item1->Title = 'a test title'; + $this->assertTrue($item1->isChanged('Title')); + } }