[8.x] Get queueable relationship when collection has non-numeric keys #37556
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.
Given there is a
Post
model with a has many relationship toTranslation
models andTranslation
models have alocale
attribute, which is unique for everyPost
. For easier accessing the relatedTranslation
models, the collection of translations could be keyed by thelocale
attribute, so that getting aTranslation
model for localenl
is possible by calling$post->translations->get('nl')
.This would be the
Post
model class.And this would be the
Translation
model class.This is where an issue arises. By dispatching a job which requires an instance of
Post
,$post->getQueueableRelations()
is called by theSerializesAndRestoresModelIdentifiers
trait. It then fails with the following errors, as demonstrated in the test in this PR.On PHP 7.3 and 7.4:
On PHP 8.0:
A solution would be to change
array_intersect(...$relations)
toarray_intersect(...array_values($relations))
, which obviously would drop any keys.I've applied this change locally and all the tests that I can run without any further configuration (some require additional modules) pass. What do you think?