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
[4.x]: Relational fields are cleared out when changing entry types #12592
Comments
It’s most likely a side effect how entry type switching works in Craft 3 vs 4. In Craft 3 there was a dedicated We’ll dig into this a bit more out of curiosity, but my guess is that the relations aren’t getting copied over during that type change autosave, as they weren’t in the previous field layout, and then end up getting deleted when the provisional draft is applied. |
I tracked this down to an order of operations bug. We're currently calling I've opened a PR to adjust this which (pending any unexpected issues) should make its way into the next release. |
Fixed for the next release via #12607! |
Awesome, thanks a lot for the quick fix! |
Craft 4.3.7 has been released with that fix. |
That change was reverted in Craft 4.3.7.1 as it was the culprit for #12623. |
What happened?
Description
If the entry type is changed for an entry, relations made in a relational field that doesn't exist in the new entry type's field layout, are removed.
This is inconsistent with how Craft retains data for all other field types (plaintext, select fields, etc) when changing an entry's entry type. It's also not how this used to work (I'm not able to reproduce the behavior on Craft 3.7.63.1).
I'm unsure if the current behavior is an intentional change in Craft 4, or a bug?
One interesting detail: From looking at the
relations
table, it doesn't look like the relations are deleted when the entry type is first changed to the type without the relational field; it's only when the entry type is changed back to the type with the relational field, that the relations are actually deleted from the database. Don't know if that's relevant or not, but seemed a bit odd to me.Steps to reproduce
Expected behavior
Existing relations made in fields that are no longer in an element's field layout after changing entry types should be retained, similar to how Craft retains data for all other field types in the same situation.
Actual behavior
Relations are deleted.
Craft CMS version
4.3.6.1
PHP version
8.1.12
Operating system and version
macOS 12.6
Database type and version
10.9.3-MariaDB
Image driver and version
No response
Installed plugins and versions
None
The text was updated successfully, but these errors were encountered: