Open
Description
BC Break Report
Q | A |
---|---|
BC Break | yes |
Version | 2.1 |
Summary
I have a document with a field with the type object_id. I try to unset this field with the query builder and a exception is thrown.
Previous behavior
In the 1.3 version it worked but I think because the driver was less strict.
Current behavior
How to reproduce
Add a field in the document User
+ /**
+ * @ODM\Field(type="object_id")
+ *
+ * @var string|null
+ */
+ protected $identifier;
+
Now we can add test in the class BuilderTest
+ public function testUnset2Field(): void
+ {
+ $qb = $this->getTestQueryBuilder()
+ ->updateOne()
+ ->field('identifier')->unsetField()
+ ->field('username')->equals('boo');
+
+ $expected = ['username' => 'boo'];
+ self::assertEquals($expected, $qb->getQueryArray());
+
+ $expected = [
+ '$unset' => ['identifier' => 1],
+ ];
+ self::assertEquals($expected, $qb->getNewObj());
+ }
The error
1) Doctrine\ODM\MongoDB\Tests\Query\BuilderTest::testUnset2Field
TypeError: MongoDB\BSON\ObjectId::__construct(): Argument #1 ($id) must be of type ?string, int given