Cakephp 2 で saveAll() メソッドを使用して一度に大量のデータを保存しようとしています。問題は、saveAll() 関数に渡す配列がどのように見えるべきかを理解していないことです。
私は次のモデルを持っています:
Recipe:
hasMany: Recipeitem
hasAndBelongsToMany:Category
Category:
hasAndBelongsToMany: Recipe
Recipeitem:
belongsTo: Recipe
hasMany: Ingredient
Ingredient:
belongsTo: Grocery, Recipeitem
Grocery:
hasMany: Ingredient
では、それぞれ 2 つの材料を含む 2 つのレシピ項目を持つレシピを保存したい場合、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
)
)
)
)
)
)
)
)