Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityToIdObjectTransformer incompatible with doctrine/orm v2.8.X #2302

Closed
mergeMarc opened this issue Apr 8, 2021 · 5 comments
Closed

EntityToIdObjectTransformer incompatible with doctrine/orm v2.8.X #2302

mergeMarc opened this issue Apr 8, 2021 · 5 comments

Comments

@mergeMarc
Copy link

mergeMarc commented Apr 8, 2021

Issue

The first constructor parameter of class EntityToIdObjectTransformer uses the type declaration Doctrine\Common\Persistence\ObjectManager.

This causes a TypeError to be thrown when a ObjectManager implementation that uses doctrine/persistence v2.X is passed.

Example

Error message:
Argument 1 passed to FOS\RestBundle\Form\Transformer\EntityToIdObjectTransformer::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of Doctrine\ORM\EntityManager given ...

Here Doctrine\ORM\EntityManager implements Doctrine\ORM\EntityManagerInterface which in turn extends Doctrine\Persistence\ObjectManager.

Cause

The doctrine/common package was separated into multiple packages (see doctrine/common#826). Use of the namespace Doctrine\Common\Persistence was deprecated and use of the new package namespace Doctrine\Persistence encouraged. The backwards compatibility layer for this deprecated namespace was eventually removed in v2.0.0 of doctrine/persistence (see doctrine/persistence#106).

Both doctrine/orm v2.8.0 and doctrine/common v3.0.0, switched to version 2 of doctrine/persistence (see doctrine/orm#8166 and doctrine/common#890).

Mitigation

Current mitigation for developers using doctrine/orm and friendsofsymfony/rest-bundle is to restrict the dependencies in their projects as follows:

File composer.json:

"require": {
    ...
    "doctrine/common": "^2.13",
    "doctrine/orm": "2.7.*",
    "doctrine/persistence": "^1.3",
    ...
}
@zatloeri
Copy link

zatloeri commented Apr 23, 2021

This is a huge issue for me and I think for anyone using php >=8
Doctine orm added support for php 8 in version 2.8 and thus we cannot roll back to 2.7.

I would really like to leverage some benefits of fos rest, but as of now I do not know how to get
around this problem.
Does anybody have any temporary workarounds to deal with this?

@xabbuh
Copy link
Member

xabbuh commented Apr 23, 2021

Does #2306 work for you?

@mergeMarc
Copy link
Author

#2306 fixes the TypeError while using doctrine/orm v2.8.4 for me.

However, I still had trouble using the Transformer due to unrelated issues: reverseTransform always returns null due to the value passed never being an array but a string (Past changes in symfony/form break functionality?). Was not able to get it working with a simple test just like the example in the docs (Maybe I’m using it wrong). Should I open an issue for that?

I ended up using form field type Symfony\Bridge\Doctrine\Form\Type\EntityType to handle validation and id to object conversion.

@xabbuh
Copy link
Member

xabbuh commented Apr 23, 2021

This rather sounds like your use case does not require the transformer at all if the EntityType already supports it.

@GuilhemN
Copy link
Member

Closing as #2306 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants