Doctrine2 / Symfony2 - Multiple objects on the same table

In a Symfony2 application, I have a MainBundle and various bundles that you can enable or not. In MainBundle, I need to have a Model and a basic Entity . In OtherBundle Entity with the same table name as Entity in MainBundle .

The luminaires in the MainBundle must be loaded with or without other bundles than the MainBundle:

MainBundle - Model - Entity (Table name "test") - Fixtures OtherBundle - Entity (Table name "test") - Fixtures OtherBundle2 - Entity (Table name="test") - Fixtures 

If I used @ORM \ MappedSuperclass for Model , @ORM \ Entity for Entity > in MainBundle and @ORM \ Entity in OtherBundle , after which Doctrine2 stops with an error, "the table already exists."

I cannot use the Inheritance table, since my model should not know about other objects in other packages. The @ORM \ DiscriminatorMap icon points to OtherBundle .

Is there any way to do this?

+6
source share
1 answer

As Jasper N. Brower mentioned, it is the same entity and the same table, so it makes no sense to do what you are trying to do.

Create your entity in a package called, for example, "SharedEntityBundle", and use resolve_target_entity to communicate with this entity from other packages, not knowing about the aphorism.

http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html

Saying there seems to be a solution with several entity managers: Symfony 2 / Doctrine 2: two objects for the same table, use one in favor of the other

+1
source

Source: https://habr.com/ru/post/951616/


All Articles