I'm using a migration script to clear out the values for a field on one of my entries. The field is an Entry Field and is not required.
So I do this:
$product->components = [];
Craft::$app->elements->saveElement($product);
But I get this error:
Argument 1 passed to craft\fields\BaseRelationField::_all() must implement interface craft\elements\db\ElementQueryInterface, array given, called in /var/www/html/vendor/craftcms/cms/src/fields/BaseRelationField.php on line 382
I can clear out other fields, even entry fields, just fine. But this particular one gives me this error every time.
I've also tried the following:
$product->components = null;
Craft::$app->elements->saveElement($product);
And:
$product->components = false;
Craft::$app->elements->saveElement($product);
Any ideas?