Skip to content

check if other instances have value before joining relations table#16919

Merged
brandonkelly merged 5 commits into5.xfrom
bugfix/16912-multi-instance-relation-fields-and-relations-table
Mar 19, 2025
Merged

check if other instances have value before joining relations table#16919
brandonkelly merged 5 commits into5.xfrom
bugfix/16912-multi-instance-relation-fields-and-relations-table

Conversation

@i-just
Copy link
Copy Markdown
Contributor

@i-just i-just commented Mar 19, 2025

Description

This can be reproduced with a single site setup and with adding a value to the relation field via the control panel:

  • clean 5.6.11 install
  • create a section relations with an entry type that can have just the default title
  • create at least one entry in the relations section
  • create an Entries field
  • create a blog section with an entry type that contains that entries field added twice
  • create an entry in the blog section, fill out the title and fully save
  • edit the entry from the previous step, add an entry to the second Entries field - let it autosave
  • reload the page - see that this relation will now show in both fields

For compatibility reasons with versions < 5.3.0, if the first instance of a relation field is null, we join in the legacy relations table and populate that first instance (as in the first one added to the layout, not the first one on the page) with its content.

This problem was exacerbated by #16818 because, when duplicating the element (e.g. to create a provisional draft), we no longer add an empty array as the value of the relation field.

Fix: if the value of the first instance of the field is null, check if we have more than one instance of it in the layout, and if so, if any of those instances have a value. If yes, then don’t join in the relations table.

(While working on this, I discovered a potential bug related to the resave job the happens with and without this change. To be discussed internally.)

Related issues

#16912

@i-just i-just requested a review from brandonkelly March 19, 2025 12:57
@brandonkelly brandonkelly merged commit 42990fd into 5.x Mar 19, 2025
@brandonkelly brandonkelly deleted the bugfix/16912-multi-instance-relation-fields-and-relations-table branch March 19, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants