Merge pull request #10923 from kinglozzer/10821-mmtl-changetracking

FIX: Stop ManyManyThroughList join records incorrectly showing as changed (fixes #10821)
This commit is contained in:
Guy Sartorelli 2023-08-24 09:05:38 +12:00 committed by GitHub
commit 2e92b89b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -87,7 +87,8 @@ class ManyManyThroughList extends RelationList
if ($joinRow) {
$joinClass = $this->manipulator->getJoinClass();
$joinQueryParams = $this->manipulator->extractInheritableQueryParameters($this->dataQuery);
$joinRecord = Injector::inst()->create($joinClass, $joinRow, false, $joinQueryParams);
$creationType = empty($joinRow['ID']) ? DataObject::CREATE_OBJECT : DataObject::CREATE_HYDRATED;
$joinRecord = Injector::inst()->create($joinClass, $joinRow, $creationType, $joinQueryParams);
$record->setJoin($joinRecord, $joinAlias);
}

View File

@ -514,4 +514,19 @@ class ManyManyThroughListTest extends SapphireTest
$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'));
}
}