Closed Steveb-p closed 4 years ago
Note to myself: check if the same thing is happening on 1.3.x branch after writing a test
It seems I'm at fault for this one (I suspected as much, it would be really strange if an issue like this was not more widespread).
The sample test presented is not what was happening in my code. In reality I was loading the document like so:
$qb = $this->createQueryBuilder();
$qb->findAndUpdate();
$qb->addAnd(
$qb->expr()->addOr(
$qb->expr()->field('locked_until')->lt(time()),
$qb->expr()->field('locked_until')->exists(false),
)
);
$document = $qb->getQuery()->execute();
What I didn't realize is that I was missing a crucial method call: $qb->returnNew();
. Therefore I got a document with null
value in locked_until
field and this resulted in ODM ignoring it (since as far as it could tell, it wasn't changed).
Thanks for updating us. I didn't get around to testing this, so I'm happy you were able to resolve this yourself.
Bug Report
Summary
When a document class is part of inheritance, fields that are set to null during update are not removed from the database.
Current behavior & How to reproduce
Consider classes declared:
and
When document is updated with
null
value it will not be$unset
.While I haven't run the test, I have it confirmed during dev by looking at
Doctrine\ODM\MongoDB\Persisters\DocumentPersister::update
.with inheritance:
without:
I was considering if maybe #2196 might be related to this, but the case seems different enough to warrant a different issue in my opinion.