doctrine/mongodb-odm

Update embed many attribute to empty array

spiider8 opened this issue · 3 comments

Q A
Version 2.0.1

Update attribut to empty array value

Hi, I hope I'm writing to the right channel. I got problem with persistence (update) with empty array value. Iam using odm and in document model got attribute "content" which is embed many like this:

#[MongoDB\EmbedMany(strategy: 'atomicSetArray', targetDocument: Content::class, storeEmptyArray: true)] private ArrayCollection $content;

When i send request on my PUT endpoint for example:

{ "attr1": "val1", "attr2": "val2", "content": [] }

And in repository:

$this->getDocumentManager()->persist($document); $this->getDocumentManager()->flush();

Nothing happens and document in db does not change the attribute "content" to empty array value but its ignored. I debugged it and that problem is maybe in the UnitOfWork class on row: 623 where is:

$coll->setDirty(! $value->isEmpty());

Can anybody help pls how to fix this issue if its possible? thx

@spiider8 to confirm it's a bug in ODM please send us a pull request with a failing test case. You can take a look at such tests here: https://github.com/doctrine/mongodb-odm/blob/2.7.x/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1964Test.php

Also please note that 2.0.1 is not supported for quite some time :)

I figured out that there was a data transformation error and I used the "OBJECT_TO_POPULATE" options during deserialization.
I am closing this issue