1
我想使用XML映射(Symfony 2 PR 7)的Doctrine 2的「類表繼承特性」。在XML超CatalogProduct的如何使用Doctrine 2中的「類表繼承」與XML映射
XML定義:XML超CatalogBook的
<?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://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="MyApp\CatalogBundle\Entity\CatalogProduct" table="catalog_product" inheritance-type="JOINED">
<discriminator-column name="discr" type="string" />
<discriminator-map>
<discriminator-mapping value="book" class="MyApp\CatalogBundle\Entity\CatalogBook" />
</discriminator-map>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
</id>
<field name="name" column="name" type="string" length="50" nullable="true" unique="false" />
<field name="isPublic" column="is_public" type="boolean" />
</entity>
</doctrine-mapping>
XML定義,應該擴展CatalogProduct:
<?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://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="MyApp\CatalogBundle\Entity\CatalogBook" table="catalog_book">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
</id>
<field name="author_name" column="author_name" type="string" length="50" nullable="true" unique="false" />
</entity>
</doctrine-mapping>
./php應用程序/控制檯學說:生成:實體「CatalogBundle」
正常工作(實體generatetd),但CatalogBook原來是一個「簡單」類,不擴展CatalogProduct。
$book = new CatalogBook();
$book->setAuthorName('some author');
$book->setName('some book name');
導致異常:
Fatal error: Call to undefined method MyApp\CatalogBundle\Entity\CatalogBook::setName()
我猜,我缺少的東西XML,它告訴CatalogBook實體延伸CatalogProduct。但是我沒有在Doctrine 2文檔或谷歌上找到任何幫助。