Thank you.
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Webweave Sent: Wednesday, January 21, 2009 4:33 PM To: CakePHP Subject: Re: Relationships - HABTM http://book.cakephp.org/view/439/recursive On Jan 19, 7:57 am, "[email protected]" <[email protected]> wrote: > 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... > > read more » --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
