I have been making some pretty good headway on defining the
relationships for my models. However I am not getting some data that I
expect to get. This may be due to my relationship definitions or a
misunderstanding of what CakePHP will do for me. I am hoping one you
can point me in the right direction.
So am I missing something here? Wrong relationship definition? Wrong
expectation?
Thanks in advance.
Steve
I have the following models and relationship definitions:
Recipe
var $hasAndBelongsToMany = array(
'Ingredient' =>
array(
'className' => 'Ingredient',
'joinTable' => 'ingredient_lists',
'foreignKey' => 'recipe_id',
'associationForeignKey' => 'ingredient_id',
'unique' => true
),
'MeasurementType' =>
array(
'className' => 'MeasurementType',
'joinTable' => 'ingredient_lists',
'foreignKey' => 'recipe_id',
'associationForeignKey' => 'measurement_type_id',
'unique' => true
)
);
IngredientList
var $belongsTo = array('Recipe', 'MeasurementType');
Ingredient
var $belongsTo = 'IngredientType';
I set the recipe for the view var in the controller like so:
$this->set('recipe', $this->Recipe->read());
I expect that when I view the recipe array in the view I should see a
multi-array. Each Ingredient array should have a sub array that
contains the ingredient, ingredient_type and measurement_type. But
this is not the case.
When I do a debug of the $this->viewVars in the view view I get the
following output. As you can see the MeasurementType array is not
under the Ingredient array.
app\views\recipes\view.ctp (line 37)
Array
(
[Recipe] => Array
(
[id] => 0000000002
[recipe] => Cranberry Orange Bake
[description] => A classic casserole with a festive flair.
[instructions] => Preheat the oven to 400 degrees.
Prepare stuffing mixture as directed on box substituting orange juice
and water for broth. Stir the cranberries and pecans in with the
stuffing mix.
Combine the soup, Quorn and vegetables. Spoon into an 13x9 baking dish
and top with the stuffing mixture.
Bake for 30min or until cooked through.
[servings] => 6
[recipe_type_id] => 0000000006
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
)
[Ingredient] => Array
(
[0] => Array
(
[id] => 0000000031
[ingredient] => stuffing mix
[ingredient_type_id] => 0000000019
[description] =>
[created] => 2009-01-09 20:10:44
[modified] => 2009-01-09 20:13:14
[IngredientList] => Array
(
[id] => 0000000005
[recipe_id] => 0000000002
[ingredient] => stuffing mix
[fractional_amount] =>
[whole_amount] => 6
[measurement_type_id] => 0000000001
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000031
)
)
[1] => Array
(
[id] => 0000000032
[ingredient] => orange juice
[ingredient_type_id] => 0000000021
[description] =>
[created] => 2009-01-09 20:13:31
[modified] => 2009-01-09 20:13:31
[IngredientList] => Array
(
[id] => 0000000006
[recipe_id] => 0000000002
[ingredient] => orange juice
[fractional_amount] =>
[whole_amount] => 1
[measurement_type_id] => 0000000002
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000032
)
)
[2] => Array
(
[id] => 0000000013
[ingredient] => water
[ingredient_type_id] => 0000000012
[description] =>
[created] => 2009-01-04 15:48:26
[modified] => 2009-01-04 15:48:26
[IngredientList] => Array
(
[id] => 0000000007
[recipe_id] => 0000000002
[ingredient] => water
[fractional_amount] => 1/2
[whole_amount] =>
[measurement_type_id] => 0000000002
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000013
)
)
[3] => Array
(
[id] => 0000000033
[ingredient] => dried cranberries
[ingredient_type_id] => 0000000020
[description] =>
[created] => 2009-01-09 20:13:48
[modified] => 2009-01-09 20:13:48
[IngredientList] => Array
(
[id] => 0000000008
[recipe_id] => 0000000002
[ingredient] => dried cranberries
[fractional_amount] => 1/3
[whole_amount] =>
[measurement_type_id] => 0000000002
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000033
)
)
[4] => Array
(
[id] => 0000000034
[ingredient] => pecans
[ingredient_type_id] => 0000000020
[description] =>
[created] => 2009-01-09 20:15:04
[modified] => 2009-01-09 20:15:04
[IngredientList] => Array
(
[id] => 0000000009
[recipe_id] => 0000000002
[ingredient] => pecans
[fractional_amount] =>
[whole_amount] => 2
[measurement_type_id] => 0000000004
[description] => crushed
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000034
)
)
[5] => Array
(
[id] => 0000000036
[ingredient] => cream of broccoli soup
[ingredient_type_id] => 0000000022
[description] =>
[created] => 2009-01-09 20:16:47
[modified] => 2009-01-09 20:16:47
[IngredientList] => Array
(
[id] => 0000000010
[recipe_id] => 0000000002
[ingredient] => cream of broccoli soup
[fractional_amount] =>
[whole_amount] => 20
[measurement_type_id] => 0000000001
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000036
)
)
[6] => Array
(
[id] => 0000000035
[ingredient] => quorn chunks
[ingredient_type_id] => 0000000014
[description] =>
[created] => 2009-01-09 20:15:55
[modified] => 2009-01-09 20:15:55
[IngredientList] => Array
(
[id] => 0000000011
[recipe_id] => 0000000002
[ingredient] => quorn chunks
[fractional_amount] =>
[whole_amount] => 12
[measurement_type_id] => 0000000001
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000035
)
)
[7] => Array
(
[id] => 0000000006
[ingredient] => broccoli
[ingredient_type_id] => 0000000006
[description] =>
[created] => 2008-12-23 12:05:02
[modified] => 2008-12-23 12:05:02
[IngredientList] => Array
(
[id] => 0000000012
[recipe_id] => 0000000002
[ingredient] => broccoli
[fractional_amount] =>
[whole_amount] => 1
[measurement_type_id] => 0000000002
[description] => chopped
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000006
)
)
[8] => Array
(
[id] => 0000000038
[ingredient] => yellow squash
[ingredient_type_id] => 0000000006
[description] =>
[created] => 2009-01-09 20:17:25
[modified] => 2009-01-09 20:17:25
[IngredientList] => Array
(
[id] => 0000000013
[recipe_id] => 0000000002
[ingredient] => yellow squash
[fractional_amount] => 1/2
[whole_amount] =>
[measurement_type_id] => 0000000002
[description] => chopped
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000038
)
)
[9] => Array
(
[id] => 0000000037
[ingredient] => zuchinni
[ingredient_type_id] => 0000000006
[description] =>
[created] => 2009-01-09 20:17:10
[modified] => 2009-01-09 20:17:10
[IngredientList] => Array
(
[id] => 0000000014
[recipe_id] => 0000000002
[ingredient] => zuchinni
[fractional_amount] => 1/2
[whole_amount] =>
[measurement_type_id] => 0000000002
[description] => chopped
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000037
)
)
[10] => Array
(
[id] => 0000000049
[ingredient] => onion
[ingredient_type_id] => 0000000001
[description] =>
[created] => 2009-01-16 10:37:04
[modified] => 2009-01-16 10:37:04
[IngredientList] => Array
(
[id] => 0000000015
[recipe_id] => 0000000002
[ingredient] => onion
[fractional_amount] => 1/4
[whole_amount] =>
[measurement_type_id] => 0000000002
[description] => chopped
[created] => 2009-01-16 10:37:04
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000049
)
)
[11] => Array
(
[id] => 0000000050
[ingredient] => potato
[ingredient_type_id] => 0000000001
[description] =>
[created] => 2009-01-16 10:37:04
[modified] => 2009-01-16 10:37:04
[IngredientList] => Array
(
[id] => 0000000016
[recipe_id] => 0000000002
[ingredient] => potato
[fractional_amount] => 1/4
[whole_amount] =>
[measurement_type_id] => 0000000002
[description] => chopped
[created] => 2009-01-16 10:37:04
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000050
)
)
)
[MeasurementType] => Array
(
[0] => Array
(
[id] => 0000000001
[measurement_type] => ounce
[created] => 2008-12-23 12:30:12
[modified] => 2009-01-04 16:47:53
[abbreviation] => oz
[IngredientList] => Array
(
[id] => 0000000005
[recipe_id] => 0000000002
[ingredient] => stuffing mix
[fractional_amount] =>
[whole_amount] => 6
[measurement_type_id] => 0000000001
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000031
)
)
[1] => Array
(
[id] => 0000000002
[measurement_type] => cup
[created] => 2008-12-23 12:30:23
[modified] => 2009-01-04 15:46:37
[abbreviation] => cp
[IngredientList] => Array
(
[id] => 0000000006
[recipe_id] => 0000000002
[ingredient] => orange juice
[fractional_amount] =>
[whole_amount] => 1
[measurement_type_id] => 0000000002
[description] =>
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000032
)
)
[2] => Array
(
[id] => 0000000004
[measurement_type] => tablespoon
[created] => 2008-12-23 12:32:10
[modified] => 2009-01-04 15:46:59
[abbreviation] => tbsp
[IngredientList] => Array
(
[id] => 0000000009
[recipe_id] => 0000000002
[ingredient] => pecans
[fractional_amount] =>
[whole_amount] => 2
[measurement_type_id] => 0000000004
[description] => crushed
[created] => 2009-01-16 10:35:19
[modified] => 2009-01-16 10:43:15
[ingredient_id] => 0000000034
)
)
)
)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---