doctrine / doctrine-laminas-hydrator

Doctrine hydrators for Laminas applications
https://www.doctrine-project.org/projects/doctrine-laminas-hydrator.html
MIT License
33 stars 19 forks source link

Assert function failing for Mongo ODM EmbedMany tag #84

Open eastern-ravindra opened 6 months ago

eastern-ravindra commented 6 months ago

https://github.com/doctrine/doctrine-laminas-hydrator/blame/81ee8121f42dcc0b6f39e08dce56b10baf6fb95f/src/DoctrineObject.php#L355

if ($metadata->hasAssociation($field)) {
                $target = $metadata->getAssociationTargetClass($field);
                assert($target !== null);

Above assert code is failing for mongoDB, when we are using EmbedMany argument without target document locally.

According to documentation, EmbedMany without target document is allowed to embed different documents in same field.(https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.7/reference/embedded-mapping.html#mixing-document-types)

Does this assert check is really needed as null value is also accepted for mongodb?

TomHAnderson commented 6 months ago

If you take out the assertion, does it work? There is this line too that expects the target: https://github.com/doctrine/doctrine-laminas-hydrator/blob/81ee8121f42dcc0b6f39e08dce56b10baf6fb95f/src/DoctrineObject.php#L373

eastern-ravindra commented 6 months ago

If you take out the assertion, does it work? There is this line too that expects the target:

https://github.com/doctrine/doctrine-laminas-hydrator/blob/81ee8121f42dcc0b6f39e08dce56b10baf6fb95f/src/DoctrineObject.php#L373

toMany function is not working in this case, giving

Doctrine\Persistence\Mapping\MappingExceptionClass '' does not exist

I think, we need to override this function where we can add conditions if $target is null