1
votes

I'm trying to figure out how the superclass mapping works in Doctrine2, and I have some examples to work with, but I've been using the xml mapping to create my Entities and then in turn the database schema. I found one example that showed an 'extends' parameter to the 'entity' tag, but it does not appear to be supported in the current schema.

How do you go about telling the XML driver what classes should extend a mapped superclass?

SW

1

1 Answers

0
votes

How do you go about telling the XML driver what classes should extend a mapped superclass?

You don't have to :)

You can simply create an abstract class (lets name it My\First\BaseClass) and define a Mapped Superclass in XML:

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping
    xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
        http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>

    <mapped-superclass name="My\First\BaseClass">

        <!-- fields, etc -->

    </mapped-superclass>

</doctrine-mapping>

Next have an Entity class extend this Mapped Superclass. You can even have an Entity class extending a Mapped Superclass which in turn extends another Mapped Superclass.

The point is: Doctrine is smart enough to traverse all XML mapping files in order to determine the complete set of mapping metadata, based on class inheritance. You don't need to specify the graph in XML.