symfony - Doctrine Class Table Inheritance with Symfony2 -
i have 2 symfony bundles. adminbundle installed. pagebundle may or may not installed.
i want define base entity called adminmodule (name, controller class, description, enabled), , pagemodule inherits adminmodule ( entities controller implement specific interface).
<?php namespace adminbundle\entity; /** * admin component * * @orm\entity * @orm\table(name="admin_module") * @orm\inheritancetype("joined") * @orm\discriminatorcolumn(name="discr", type="string") * @orm\discriminatormap({"page" = "\pagebundle\entity\pagecomponent"}) */ class adminmodule { // private vars, getters, setters } ?> <?php namespace pagebundle\entity; use adminbundle\entity\adminmodule; /** * page component * * @orm\entity * @orm\table(name="page_module") */ class pagemodule extends adminmodule { // } ?> the issue have, think, adminmodule annotation @orm\discriminatormap({"page" = "\pagebundle\entity\pagemodule"}) requires definition on adminbundle - pagebundle may not installed.
i believe must have wrong type of inheritance structure (?) not clear on alternative approaches can take? or direction :)
you can't you're trying table inheritance mappings, because have write annotations in parent class, parent class ends being coupled children.
what use mapped superclass (@mappedsuperclass) extend actual parent entities from.
all common properties should go mapped superclass, using children actual entities define different inheritance mappings , associations (association mappings in mapped superclasses limited).
so in specific case have such structure:
/** * i'm not actual entity! * * @mappedsuperclass */ class modulesuperclass {} /** * don't have children * * @orm\entity */ class basemodule extends modulesuperclass {} /** * have children * * @orm\entity * @orm\inheritancetype("joined") * @orm\discriminatorcolumn(name="discr", type="string") * @orm\discriminatormap({"page" = "page"}) */ class adminmodule extends modulesuperclass {} /** * i'm child * * @orm\entity */ class pagemodule extends adminmodule {} your mileage may of course vary, i.e. rather have basemodule class without children, , basemodule in entirely different namespace extend both adminmodule , pagemodule from.
Comments
Post a Comment