【发布时间】:2012-08-04 15:26:47
【问题描述】:
我在 Symfony2 中加载 Propel 固定装置时遇到问题。我有以下架构:
<table name="application" phpName="Application">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="varchar" required="true" primaryString="true" />
<behavior name="timestampable" />
</table>
<table name="application_iphone" phpName="IphoneApplication">
<column name="store_id" type="varchar" required="true" />
<behavior name="concrete_inheritance">
<parameter name="extends" value="application" />
</behavior>
</table>
<table name="application_identifier" phpName="IphoneApplicationIdentifier">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="application_id" required="true" type="integer" />
<column name="identifier" type="varchar" required="true" primaryString="true" />
<foreign-key foreignTable="application_iphone">
<reference local="application_id" foreign="id" />
</foreign-key>
</table>
模型构建正确。当我尝试加载以下固定装置时会出现问题:
Acme\MyBundle\Model\Application:
first_app:
name: "MyFirstApp"
descendant_class: "IphoneApplication"
Acme\MyBundle\Model\IphoneApplication:
first_app_iphone:
id: first_app
store_id: 2342
Acme\MyBundle\Model\IphoneApplicationIdentifier:
first_app_identifier:
identifier: "com.acme.myfirstapp.appstore"
application_id: first_app_iphone
出现以下错误:
[推进]异常
无法为自增主键 (application.ID) 插入值
我添加了两次“first_app”应用程序(一次在 Application 中,另一次在 IphoneApplication 中)以防止我的 IphoneApplicationIdentifier 出现另一个问题夹具:
[Propel] 异常来自类的对象“first_app” “Acme\MyBundle\Model\Application”未在您的数据文件中定义。
如何为具体的继承模型插入固定装置?
【问题讨论】:
-
遇到了同样的问题...您是否尝试从灯具中删除 id?
-
是的,我已经尝试过了。但是,如果我删除它,我会在数据库中插入两个应用程序(而不是一个):基本应用程序和与 iPhone 对应的另一个应用程序。 ://
标签: php symfony propel fixtures concrete-inheritance