Skip to content

Loading…

DDC-2436: Inheritance on mappedSuperClass #3151

Closed
doctrinebot opened this Issue · 8 comments

2 participants

@doctrinebot

Jira issue originally created by user pcastrotigre:

Sometimes is necessary some associations(many to many) in the mappedSuperClass. This associations should not be lost (inversedBy side and mappedBy ). The only one way to get this, was to implement an abstract class as Single Inheritance Table and then the mappedSuperClass inherit of this. But this is not optimum, because we are losing the OOP, creating classes which should not exist.

I realized of this when i was creating my bundle to be used for some projects, but I needed each project could extends from my class and add some properties or methods according their needs.

This is the link where you can see more details of this:

http://stackoverflow.com/questions/16405556/mapped-super-class-symfony2-2

Thanks for your attention.

@doctrinebot

Comment created by @ocramius:

Mapped superclasses cannot be referenced as they are only meant to provide some simplification by allowing inherited mappings in child classes.

If you want to enforce some kind of association in third party libraries, you can define interfaces and reference those: then, with a listener (during the onLoadMetadata event), replace the interfaces in mappings with (configured) concrete class names.

@doctrinebot

Issue was closed with resolution "Invalid"

@doctrinebot

Comment created by pcastrotigre:

I did it, and everything worked perfectly. However, is there a way to dynamically change the "resolvetargetentities" inside my LoadClassMetadata or inside my php code?.
I would like the user makes this configurations with params from my bundle. In background, my bundle will configure these params for doctrine.
Could i do that?

Thanks again for your attention.

@doctrinebot

Comment created by pcastrotigre:

I was thinking in duplicate some code of yours. Exactly this one:

$def = $container->findDefinition('doctrine.orm.listeners.resolve*target*entity');
foreach ($config['resolve*target*entities'] as $name => $implementation) {
     $def->addMethodCall('addResolveTargetEntity', array(
     $name, $implementation, array()
     ));
}
@doctrinebot

Comment created by @ocramius:

That's exactly how this has to be done.

@doctrinebot

Comment created by pcastrotigre:

I did but there is a problem.... The service doctrine.orm.listeners.resolvetargetentity is not public. So i can't use it in my bundle. I wouldn't like to duplicate all code from this Service. How could I do?

@doctrinebot

Comment created by @ocramius:

That's an issue for the DoctrineBundle, not for the ORM.

@doctrinebot

Comment created by pcastrotigre:

Ok thanks a lot for your help. I will redirect my question to them.

@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.