-
Notifications
You must be signed in to change notification settings - Fork 642
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]: BaseRelationField::normalizeValue $value can be instance of Collection #14117
Comments
If it’s already a collection, I’m pretty sure this would have worked too: if ($value instanceof ElementQueryInterface || $value instanceof Collection) {
return $value;
} Can you verify that‘s going to work for you? |
doh |
Thanks for confirming! Craft 4.5.15 and 4.6.0 are out with that change. |
@brandonkelly I'm now seeing this when trying to update to 4.6:
Could it be related to this fix? |
This was when programatically setting a relation field to a collection. Worked in 4.5.14. Fixed it for 4.6.0 by using |
@boboldehampsink Setting the value to a collection of integers wouldn’t have actually done anything. The only values that were supported before 4.5.15 are:
Anything else would cause |
Check! |
What happened?
Description
in addition to #11667, #11670, and #13421
BaseRelationField::normalizeValue
$value
can be instance of Collection instead of an Element Query as well.When applying drafts in the CP and a relation field is eager loaded due to performance reasons, your
craft\services\Elements::duplicateElement
does the following:clone $value
is an instance ofcraft\elements\ElementCollection
however yourBaseRelationField
will ignore thatI was able to fix this by adding a type check
Steps to reproduce
Expected behavior
Actual behavior
Craft CMS version
4.5.14
PHP version
8.2.0
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
No response
The text was updated successfully, but these errors were encountered: