【发布时间】:2015-07-01 18:16:20
【问题描述】:
我正在尝试弄清楚如何正确映射我的实体,以便我可以进行 Doctrine 2 类表继承 (Doc here)
所以我尝试了许多不同的解决方案,但我似乎无法使用命令行工具 (doctrine:schema:validate) 验证我的模型
这就是我所尝试的。我还没有更改父类,所以我将其留在这里。
Api\TestBundle\Entity\Item:
type: entity
table: items
inheritanceType: JOINED
discriminatorColumn:
name: type
type: string
nullable: false
length: 32
fixed: false
comment: ''
discriminatorMap:
item_property_facebook: ItemPropertyFacebook
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: AUTO
fields:
bundledType:
type: string
nullable: false
length: 32
fixed: false
comment: ''
column: bundled_type
lifecycleCallbacks: { }
对于子类,我先放了另一个id:
Api\TestBundle\Entity\ItemPropertyFacebook:
type: entity
table: item_property_facebook
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: AUTO
fields:
account_id:
type: integer
lifecycleCallbacks: { }
显然,我明白了:
Duplicate definition of column 'id' on entity 'Api\TestBundle\Entity
\ItemPropertyFacebook' in a field or discriminator column mapping.
所以我尝试删除孩子中的 id 定义,我得到:
No identifier/primary key specified for Entity "Api\TestBundle\Entit
y\ReferenceItemPropertyFacebook". Every Entity must have an identifier/prim
ary key.
所以我完全不知道。在文档中,他们只设置了基本的东西,但没有设置 id,我在网上找不到任何东西,因为我可能没有很好地制定它。我读到了 associationKey,但是当我尝试过时,Doctrine 告诉我同样的情况
No identifier/primary key specified for Entity "Api\TestBundle\Entit
y\ReferenceItemPropertyFacebook". Every Entity must have an identifier/prim
ary key.
如果您有任何线索,我将不胜感激。非常感谢!
【问题讨论】:
-
您是否在您的 ItemPropertyFacebook 类中扩展了 Item 类?无论如何,您必须删除子类中的 id 属性。
-
是的,我的 ItemPropertyFacebook 类扩展了 Item
标签: php symfony doctrine-orm doctrine yaml