我正在尝试使用 cakephp 2 中的 saveAll() 方法一次保存大量数据。问题是我不明白我传递给 saveAll() 函数的数组应该是什么样子。
我有以下型号:
Recipe:
hasMany: Recipeitem
hasAndBelongsToMany:Category
Category:
hasAndBelongsToMany: Recipe
Recipeitem:
belongsTo: Recipe
hasMany: Ingredient
Ingredient:
belongsTo: Grocery, Recipeitem
Grocery:
hasMany: Ingredient
因此,如果我想保存一个包含两个配方项的配方,每个配方项有两种成分,那么我传递给 saveAll 函数的数组对象应该是什么样的?
这是我的数组目前的样子:
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
)
)
)
)
)
)
)
)