2011-03-09 2 views
1

Doctrine 2の "クラステーブル継承機能"をXMLマッピング(Symfony 2 PR 7)で使用しようとしています。 XMLスーパーCatalogProductのDoctrine 2のXMLマッピングでの "class table inheritance"の使い方

XML定義:CatalogProductを拡張する必要があります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定義:

<?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アプリ/コンソール教義:生成:エンティティ"CatalogBu​​ndle"

がうまくいきますが、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() 

私は、私はCatalogProductを拡張するCatalogBookエンティティを伝えるXMLで何かを、欠けていると思います。しかし、Doctrine 2のドキュメンテーションやGoogleの助けを借りて何かを見つけることはできません。

答えて

1

エンティティを生成しても、意味的に不可能なため、継承階層は生成されません。 doctrine:generate:エンティティを呼び出した後で、自分で行う必要があります。

関連する問題