Skip to content

updateMany() does not serialize EmbeddedDocument documents in embedded documents fields. #2825

@landure

Description

@landure

Bug Report

Q A
BC Break yes
Version 2.12.1

Summary

Current behavior

updateMany() accepts to set EmbeddedDocument in fields (field name is field.target) but it stores an empty document {} in the target field.
It works for root fields (field name is target).

I believe this worked in version 2.7.0.

How to reproduce

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

#[ODM\EmbeddedDocument()]
class Embedded {
 public function __construct(
        #[ODM\Field(type: 'string')]
        #[ODM\Index()]
        private string $name,
}
}

#[ODM\EmbeddedDocument()]
class RootEmbedded {
 public function __construct(
        #[ODM\EmbedOne(targetDocument: Embedded::class)]
        private Embedded $embedded;
}
}

#[ODM\Document()]
class MainDocument {
    #[ODM\EmbedOne(targetDocument: RootEmbedded::class)]
        private RootEmbedded $field;

        #[ODM\EmbedOne(targetDocument: Embedded::class)]
        private Embedded $embedded;
}

In MainDocumentRepository:

        $qb = $this->createQueryBuilder();
        $qb->updateMany()
            ->field('root.embedded.name')->equals($embedded->getName())
            ->field('embedded')->set($embedded)  // works
            ->field('root.embedded')->set($embedded) // doesn't work, store `{}`
            ->getQuery()
            ->execute();

Expected behavior

updateMany() accepts to set EmbeddedDocument in fields of embedded documents (when the field name is field.target), and stores the full document { "name": "value" } in the target field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions