[英]Symfony2, Propel fixtures and concrete inheritance
I got an issue with Propel fixtures loading in Symfony2. 我在Symfony2中加载了Propel灯具问题。 I have the following schema:
我有以下架构:
<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>
The model builds correctly. 该模型正确构建。 The issue raises when I try to load the following fixtures:
当我尝试加载以下灯具时,问题就出现了:
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
The following error occurs: 发生以下错误:
[Propel] Exception
[推动]例外
Cannot insert a value for auto-increment primary key (application.ID)无法为自动增量主键(application.ID)插入值
I added my "first_app" application twice (one in Application , another time in IphoneApplication ) to prevent from another issue with my IphoneApplicationIdentifier fixture: 我添加了两次“first_app”应用程序(一次在Application中 ,另一次在IphoneApplication中 )以防止我的IphoneApplicationIdentifier夹具出现另一个问题:
[Propel] Exception The object "first_app" from class "Acme\\MyBundle\\Model\\Application" is not defined in your data file.
[Propel] Exception类“Acme \\ MyBundle \\ Model \\ Application”中的对象“first_app”未在数据文件中定义。
How can I insert fixtures for a concrete inheritant model? 如何为具体的继承模型插入夹具?
Propel is telling you that you are trying to set a value for an autoincrement column, this is due to the Propel告诉你,你正在尝试为自动增量列设置一个值,这是由于
id: first_app
line. 线。
If I am understanding you correctly, you just want to add an Iphoneapplication item, is that right? 如果我正确理解你,你只想添加一个Iphoneapplication项目,是吗? If that is the case you just need to do:
如果是这种情况你只需要做:
Acme\MyBundle\Model\IphoneApplication:
first_app_iphone:
name: "MyFirstApp"
store_id: 2342
I had similar situation and ended up with having different schema files. 我有类似的情况,最终有不同的架构文件。 For testing one - I removed auto-increment from schema and defined another place for storing models.
为测试一个 - 我从架构中删除了自动增量,并为存储模型定义了另一个位置。 It was long time ago, but general steps were as below:
很久以前,但一般步骤如下:
Dump fixtures for prod environment 用于生产环境的倾倒装置
app/console propel:fixtures:dump
Build everything you need for testing database 构建测试数据库所需的一切
app/console propel:database:create --env=test app/console propel:sql:build --env=test app/console propel:sql:insert --force --env=test app/console propel:model:build --env=test
Imported fixtures into test database 将导入的灯具导入测试数据库
app/console propel:fixtures:load --env=test
Note, that commands may vary depending on version of Propel 请注意,命令可能因Propel的版本而异
I found the mistake by explaining my problem in details. 我通过详细解释我的问题找到了错误。 The issue did not come from this fixtures file.
问题不是来自这个灯具文件。 The error I had seemed strange to me.
我的错误对我来说似乎很奇怪。 Why the error mentioned *first_app* instead of *iphone_first_app*?
为什么错误提到* first_app *而不是* iphone_first_app *?
After digging into the other fixtures files, I found a forgotten reference to *first_app*. 在深入研究其他灯具文件后,我发现了对* first_app *的遗忘引用。 The solution is simply the following (as mentioned by Carlos Granados):
解决方案就是以下内容(如Carlos Granados所述):
Acme\MyBundle\Model\IphoneApplication:
first_app_iphone:
name: "My first app"
store_id: 2342
Acme\MyBundle\Model\IphoneApplicationIdentifier:
first_app_identifier:
identifier: "com.acme.myfirstapp.appstore"
application_id: first_app_iphone
There is no need to define base class. 无需定义基类。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.