doctrine / DoctrineMongoDBBundle

Integrates Doctrine MongoDB ODM with Symfony
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
MIT License
377 stars 229 forks source link

Add DocumentValueResolver and MapDocument #774

Closed franmomu closed 1 year ago

franmomu commented 1 year ago

Alternative to https://github.com/doctrine/DoctrineMongoDBBundle/pull/773

Since we cannot use EntityValueResolver and MapEntity, this is an alternative to make it work.

The problem is that since Symfony 6.3, because targeted resolvers, MapEntity cannot be used when using ORM + ODM.

Closes #770 Closes #773

GromNaN commented 1 year ago

What is the actual issue that requires a dedicated DocumentValueResolver? In your proposition, this resolver is a proxy to EntityValueResolver and does nothing different.

The #[MapEntity] works as expected in my demo project on Doctrine ODM. https://github.com/GromNaN/symfony-demo/blob/60eb116cf2b6a0f9acc0bc6591d70f4a4c9f2c69/src/Controller/BlogController.php#L103

Is it to allow using both ORM and ODM in the same project and avoiding the autowiring alias on Doctrine\Persistence\ManagerRegistry: '@doctrine_mongodb' : https://github.com/GromNaN/symfony-demo/blob/60eb116cf2b6a0f9acc0bc6591d70f4a4c9f2c69/config/services.yaml#L40

franmomu commented 1 year ago

Is it to allow using both ORM and ODM in the same project and avoiding the autowiring alias on Doctrine\Persistence\ManagerRegistry: '@doctrine_mongodb' : https://github.com/GromNaN/symfony-demo/blob/60eb116cf2b6a0f9acc0bc6591d70f4a4c9f2c69/config/services.yaml#L40

Exactly, the problem is having both ORM and ODM and since MapEntity is tied to EntityValueResolver by its FQCN I couldn't come up with something better 😞

GromNaN commented 1 year ago

An alternative could be to have a ManagerRegistry aggregator embedding both ORM and ODM implementations that can be used whether it's an entity or a document.

All in all, I find your approach interesting because it avoids having to use "entity" word for "document". And it doesn't require a lot of specific code.