Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ManyManyThroughList join record flags all fields as changed #10821

Closed
kinglozzer opened this issue Jun 14, 2023 · 1 comment
Closed

ManyManyThroughList join record flags all fields as changed #10821

kinglozzer opened this issue Jun 14, 2023 · 1 comment

Comments

@kinglozzer
Copy link
Member

kinglozzer commented Jun 14, 2023

Affects 4.x and 5.x

When saving changes to a join record in a many-many-through relation, DataObject::getChangedFields() will report all fields as changed. This is because ManyManyThroughList::createDataObject() creates the join record as though it’s a brand new DataObject, not one that already exists in the database:

// Create joined record
if ($joinRow) {
$joinClass = $this->manipulator->getJoinClass();
$joinQueryParams = $this->manipulator->extractInheritableQueryParameters($this->dataQuery);
$joinRecord = Injector::inst()->create($joinClass, $joinRow, false, $joinQueryParams);
$record->setJoin($joinRecord, $joinAlias);
}

Using DataObject::CREATE_HYDRATED resolves this:

$joinRecord = Injector::inst()->create($joinClass, $joinRow, DataObject::CREATE_HYDRATED, $joinQueryParams);

PR

@GuySartorelli
Copy link
Member

Pull request merged. It'll be automatically tagged by GitHub Actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants