1
我試圖用cakephp 2中的saveAll()方法一次保存大量數據。問題是我不明白我傳遞給saveAll()函數的數組應該是什麼樣子。Cakephp - saveall() - 這個arrray應該是什麼樣的?
我有以下型號:
Recipe:
hasMany: Recipeitem
hasAndBelongsToMany:Category
Category:
hasAndBelongsToMany: Recipe
Recipeitem:
belongsTo: Recipe
hasMany: Ingredient
Ingredient:
belongsTo: Grocery, Recipeitem
Grocery:
hasMany: Ingredient
所以,如果我想保存配方有兩個recipeitems每兩種成分,我應該說我傳遞給白水函數查找數組對象喜歡?
這是我的陣列看起來像此刻:現在
Array
(
[Recipe] => Array
(
[title] => Mushroom pie
[instructions] => Just mix it!
[cooking_time] => 20
)
[Category] => Array
(
[Category] => Array
(
[0] => 5
[1] => 3
)
)
[Recipeitem] => Array
(
[0] => Array
(
[Recipeitem] => Array
(
[name] => Crust
[order] => 0
[Ingredients] => Array
(
[0] => Array
(
[Ingredient] => Array
(
[amount] => 2
[unit] => dl
[order] => 0
[Grocery] => Array
(
[name] => Butter
[description] => Butter
)
)
),
[1] => Array
(
[Ingredient] => Array
(
[amount] => 3
[unit] => dl
[order] => 1
[Grocery] => Array
(
[name] => Sugar
[description] => Sugar
)
)
)
)
)
),
[1] => Array
(
[Recipeitem] => Array
(
[name] => Filling
[order] => 1
[Ingredients] => Array
(
[0] => Array
(
[Ingredient] => Array
(
[amount] => 2
[unit] => dl
[order] => 0
[Grocery] => Array
(
[name] => Mushroom
[description] => Mushroom
)
)
)
)
)
)
)
)
[文章我寫了一篇關於它(http://www.pabloleanomartinet.com/cakephp-2-x-saving-and- validate-a-habtm-relation-example /)其他日子..可能有助於:) – pleasedontbelong