Error clearing a field via migration script 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-&gt;components = [];
Craft::$app-&gt;elements-&gt;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-&gt;components = null;
Craft::$app-&gt;elements-&gt;saveElement($product);


And:

$product-&gt;components = false;
Craft::$app-&gt;elements-&gt;saveElement($product);


Any ideas?
I figured it out. I'm not sure understand the why of it. But here is the how:

$product-&gt;setFieldValue('components', []);
Craft::$app-&gt;elements-&gt;saveElement($product);


I guess setFieldValue() does some other stuff in it that the magic methods do not.

The more you know! :)