When normalising relation field value, respect the empty array #16428
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Issue:
.eagerly()
) to get content of both field instancesSolution:
When normalising the relation field value and the value passed to the method is an empty array, it means that the target IDs are already stored in the
elements_sites.content
column but as an empty array (the field is empty). Having a value there, even if it’s an empty array, means that the content was saved since v5.3.0, and the field is supposed to be empty.Passing an empty array to the query means that the
getEagerLoadingMap()
method sees the value as an array, which means it then doesn’t attempt to check if the field is the first instance and incorrectly assign the content of the other instance of this field from the relations table.Related issues
#16191
Detailed replication steps
blog
channel with an entry type (it doesn’t have to have any fields; just the title will suffice)relatedEntries
Entries field, which has sources set to theblog
channelcollection
channel with an entry type that has therelatedEntries
field in it added twice; the second instance should have the handle changed tomoreRelatedEntries
blog
entrycollection
channel; leave therelatedEntries
field empty; add ablog
entry to themoreRelatedEntries
field;collection
channel should contain the following code:the collection entry added to the
moreRelatedEntries
shows up in both themoreRelatedEntries
andrelatedEntries
fieldif you only add an entry to the
relatedEntries
, it will only show for that field, and themoreRelatedEntries
will be empty - as expectedif you add entries to both
relatedEntries
andmoreRelatedEntries
fields, the contents of both will show as expectedif you swap the order of the
relatedEntries
andmoreRelatedEntries
fields and then, in the collection entry, fill out only therelatedEntries
field, leaving themoreRelatedEntries
field empty, themoreRelatedEntries
will incorrectly load the content of therelatedEntries
field