Dynamic targetEntity #5056

Closed
opened 2026-01-22 14:57:25 +01:00 by admin · 6 comments
Owner

Originally created by @deviprsd on GitHub (Mar 19, 2016).

Originally assigned to: @Ocramius on GitHub.

I want dynamic entity mapping on one entity which will be used by other entities. For example, I have a File entity, which will store mime type, mapping key, name etc, also an entity_id which will contain the id to the entity it belongs to. The mapping key will determine the class as this file entity will be ManyToMany. So the targetEntity for File entity isn't fixed. How to achieve that?

Originally created by @deviprsd on GitHub (Mar 19, 2016). Originally assigned to: @Ocramius on GitHub. I want dynamic entity mapping on one entity which will be used by other entities. For example, I have a File entity, which will store mime type, mapping key, name etc, also an entity_id which will contain the id to the entity it belongs to. The mapping key will determine the class as this file entity will be ManyToMany. So the targetEntity for File entity isn't fixed. How to achieve that?
admin added the Can't Fix label 2026-01-22 14:57:25 +01:00
admin closed this issue 2026-01-22 14:57:26 +01:00
Author
Owner

@Ma27 commented on GitHub (Mar 20, 2016):

For a dynamic resolve of target entities the ResolveTargetEntityListener can be used:
http://docs.doctrine-project.org/en/latest/cookbook/resolve-target-entity-listener.html

@Ma27 commented on GitHub (Mar 20, 2016): For a dynamic resolve of target entities the `ResolveTargetEntityListener` can be used: http://docs.doctrine-project.org/en/latest/cookbook/resolve-target-entity-listener.html
Author
Owner

@deviprsd commented on GitHub (Mar 20, 2016):

Yeah but that only resolves one entity, I want to resolve multiple entities with one mapping. Is that possible?

@deviprsd commented on GitHub (Mar 20, 2016): Yeah but that only resolves one entity, I want to resolve multiple entities with one mapping. Is that possible?
Author
Owner

@Ocramius commented on GitHub (Mar 20, 2016):

You can resolve to a different entity before booting the ORM, each time to an entity of your choice. Swapping the resolved target entity at runtime is not supported.

@Ocramius commented on GitHub (Mar 20, 2016): You can resolve to a different entity before booting the ORM, each time to an entity of your choice. Swapping the resolved target entity at runtime is not supported.
Author
Owner

@deviprsd commented on GitHub (Mar 20, 2016):

I wanted during runtime, so never mind.

@deviprsd commented on GitHub (Mar 20, 2016): I wanted during runtime, so never mind.
Author
Owner

@deviprsd commented on GitHub (Mar 20, 2016):

Also, I posted the same question in stack overflow, but more detailed.
http://stackoverflow.com/questions/36104055/dynamic-target-entity-doctrine-2-and-symfony-2

Can you answer with respective to this?

@deviprsd commented on GitHub (Mar 20, 2016): Also, I posted the same question in stack overflow, but more detailed. http://stackoverflow.com/questions/36104055/dynamic-target-entity-doctrine-2-and-symfony-2 Can you answer with respective to this?
Author
Owner

@inceddy commented on GitHub (May 24, 2017):

Did you make any progress on this? I stumbled across this while thinking about attaching "Comment" entities to several other entities with "CommentableInterface".

@inceddy commented on GitHub (May 24, 2017): Did you make any progress on this? I stumbled across this while thinking about attaching "Comment" entities to several other entities with "CommentableInterface".
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5056