Cakephp-saveall()-arrray应该是什么样子?
我试图使用CakePHP2中的saveAll方法一次保存大量数据。问题是我不明白传递给saveAll函数的数组应该是什么样子 我有以下型号:Cakephp-saveall()-arrray应该是什么样子?,php,cakephp,cakephp-2.0,cakephp-2.1,Php,Cakephp,Cakephp 2.0,Cakephp 2.1,我试图使用CakePHP2中的saveAll方法一次保存大量数据。问题是我不明白传递给saveAll函数的数组应该是什么样子 我有以下型号: Recipe: hasMany: Recipeitem hasAndBelongsToMany:Category Category: hasAndBelongsToMany: Recipe Recipeitem: belongsTo: Recipe hasMany: Ingredient Ingredient: belongsTo: Grocery,
Recipe:
hasMany: Recipeitem
hasAndBelongsToMany:Category
Category:
hasAndBelongsToMany: Recipe
Recipeitem:
belongsTo: Recipe
hasMany: Ingredient
Ingredient:
belongsTo: Grocery, Recipeitem
Grocery:
hasMany: Ingredient
因此,如果我想保存一个包含两个recipeitems(每个recipeitems包含两种成分)的配方,那么传递给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
)
)
)
)
)
)
)
我现在通过更好地阅读CakePHP食谱解决了这个问题: 在版本2.1中更改:您现在可以将更深层次的关联数据另存为 设置$options['deep']=true,效果良好 所以对我来说,这就是我所需要的:
$saveOptions['deep'] = true;
if ($this->Recipe->saveAll($this->request->data, $saveOptions )) {
前几天。。可能有助于: