Doctrine table class inheritance when one subclass has no extra attributes

前端 未结 5 1625
情歌与酒
情歌与酒 2021-02-13 02:31

I\'m having a problem with my mapping. I can\'t get it to work. I have an abstract base class like so:

/**
 * @Entity
 * @Table(name=\"actions\")
 * @Inheritance         


        
5条回答
  •  半阙折子戏
    2021-02-13 03:02

    Maybe this can help or add something new. It is not a how to answer but simply taking about concepts.

    If you think on classes and you understand your model as: AbstractAction, FooAction and BarAction it is probably because you can have the same methods implemented in a different way on the subclasses or extending some parent method.

    If you choose to represent these classes with tables and you choose the "all in one table with a discriminator attribute" i think you have no problem. For the BarAction you will have register with discriminator="BarAction" which will be reprsented by a BarAction.php entity class.

    On the other hand if you opt for using different table I consider you need one table per "class". The table for BarAction will only containd the ID field for the AbstractAction but its is required to "classify" (or discriminate) your data as a FooAction.

    In summary, I think three tables representing three classes are a fine solution, although the BarAction table simply contains a "link" to the parent table.

提交回复
热议问题