[英]Symfony2, Propel fixtures and concrete inheritance
我在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] Exception類“Acme \\ MyBundle \\ Model \\ Application”中的對象“first_app”未在數據文件中定義。
如何為具體的繼承模型插入夾具?
Propel告訴你,你正在嘗試為自動增量列設置一個值,這是由於
id: first_app
線。
如果我正確理解你,你只想添加一個Iphoneapplication項目,是嗎? 如果是這種情況你只需要做:
Acme\MyBundle\Model\IphoneApplication:
first_app_iphone:
name: "MyFirstApp"
store_id: 2342
我有類似的情況,最終有不同的架構文件。 為測試一個 - 我從架構中刪除了自動增量,並為存儲模型定義了另一個位置。 很久以前,但一般步驟如下:
用於生產環境的傾倒裝置
app/console propel:fixtures:dump
構建測試數據庫所需的一切
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
將導入的燈具導入測試數據庫
app/console propel:fixtures:load --env=test
請注意,命令可能因Propel的版本而異
我通過詳細解釋我的問題找到了錯誤。 問題不是來自這個燈具文件。 我的錯誤對我來說似乎很奇怪。 為什么錯誤提到* first_app *而不是* iphone_first_app *?
在深入研究其他燈具文件后,我發現了對* first_app *的遺忘引用。 解決方案就是以下內容(如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
無需定義基類。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.