RE: Relationships - HABTM

2009-01-21 Thread Steven Wright
Thank you.


 

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] 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, "rhythmicde...@gmail.com"
 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] => 02
>             [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] => 06
>             [created] => 2009-01-16 10:35:19
>             [modified] => 2009-01-16 10:43:15
>         )
>
>     [Ingredient] => Array
>         (
>             [0] => Array
>                 (
>                     [id] => 31
>                     [ingredient] => stuffing mix
>                     [ingredient_type_id] => 19
>                     [description] =>
>                     [created] => 2009-01-09 20:10:44
>                     [modified] => 2009-01-09 20:13:14
>                     [IngredientList] => Array
>                         (
>                             [id] => 05
>                             [recipe_id] => 02
>                             [ingredient] => stuffing mix
>                             [fractional_amount] =>
>                             [whole_amount] => 6
>                             [measurement_type_id] => 01
>                             [description] =>
>                             [created] => 2009-01-16 10:35:19
>                             [modified] => 2009-01-16 10:43:15
>                             [ingredient_id] => 31
>                         )
>
>                 )
>
>             [1] => Array
>                 (
>                     [id] => 32
>  

Re: Relationships - HABTM

2009-01-21 Thread Webweave
http://book.cakephp.org/view/439/recursive

On Jan 19, 7:57 am, "rhythmicde...@gmail.com"
 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] => 02
>             [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] => 06
>             [created] => 2009-01-16 10:35:19
>             [modified] => 2009-01-16 10:43:15
>         )
>
>     [Ingredient] => Array
>         (
>             [0] => Array
>                 (
>                     [id] => 31
>                     [ingredient] => stuffing mix
>                     [ingredient_type_id] => 19
>                     [description] =>
>                     [created] => 2009-01-09 20:10:44
>                     [modified] => 2009-01-09 20:13:14
>                     [IngredientList] => Array
>                         (
>                             [id] => 05
>                             [recipe_id] => 02
>                             [ingredient] => stuffing mix
>                             [fractional_amount] =>
>                             [whole_amount] => 6
>                             [measurement_type_id] => 01
>                             [description] =>
>                             [created] => 2009-01-16 10:35:19
>                             [modified] => 2009-01-16 10:43:15
>                             [ingredient_id] => 31
>                         )
>
>                 )
>
>             [1] => Array
>                 (
>                     [id] => 32
>                     [ingredient] => orange juice
>                     [ingredient_type_id] => 21
>                     [description] =>
>                     [created] => 2009-01-09 20:13:31
>                     [modified] => 2009-01-09 20:13:31
>                     [IngredientList] => Array
>                         (
>                             [id] => 06
>                             [recipe_id] => 02
>                             [ingredient] => orange juice
>                             [fractional_amount] =>
>                             [whole_amount] => 1
>                             [measurement_type_id] => 02
>                             [description] =>
>                             [created] => 2009-01-16 10:35:19
>                             [modified] => 2009-01-16 10:43:15
>                             [ingredient_id] => 32
>                         )
>
>                 )
>
>             [2] => Array
>  

RE: Relationships - HABTM

2009-01-19 Thread Steven Wright

Ok thanks I will look into the recursive option.  

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of brian
Sent: Monday, January 19, 2009 10:50 PM
To: cake-php@googlegroups.com
Subject: Re: Relationships - HABTM


That depends on what $this->Recipe->recursive is set to.

On Mon, Jan 19, 2009 at 4:34 PM, Steven Wright 
wrote:
>
> Hi Brian one more thing for clarification. My expectation is that if I 
> define the relationships correctly and my DB table are keyed correctly 
> when I call for a read all from the Recipe model I should all related 
> information from all tables no matter how deep the relationship. Is that
correct?
>
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On 
> Behalf Of brian
> Sent: Monday, January 19, 2009 1:13 PM
> To: cake-php@googlegroups.com
> Subject: Re: Relationships - HABTM
>
>
> Both Recipe and Ingredient should be HABTM with each other. You can 
> have many recipes which share ingredients. The join table for both would
be:
>
> ingredients_recipes
> ingredient_id,
> recipe_id
>
> You could add an id primary key in there, also, as it might come in handy.
> It's not required, though.
>
> As for IngredientList, I'm not sure I've never thought much about 
> doing this with Cake. I guess you could put the amount info, etc. in 
> the ingredients_recipes join table but I'm not sure that'd be the best
way.
>
> On Mon, Jan 19, 2009 at 12:50 PM, Steven Wright 
> 
> wrote:
>>
>> Hi Brian thanks for writing back.
>>
>> The ingredient_lists table is where the ingredient, amount and 
>> ingredient level instructions are stored. I suppose it's really a 
>> join table for recipes, ingredients and measurement_types. So from 
>> your reply I should actually rename this to ingredients_recipes.
>>
>> And you are saying that the Ingredient model gets the HABTM instead 
>> of Recipe. Is that correct?
>>
>>
>>
>>
>> -Original Message-
>> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On 
>> Behalf Of brian
>> Sent: Monday, January 19, 2009 12:26 PM
>> To: cake-php@googlegroups.com
>> Subject: Re: Relationships - HABTM
>>
>>
>> On Mon, Jan 19, 2009 at 10:57 AM, rhythmicde...@gmail.com 
>>  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 don't understand what you're doing with the ingredient_lists table.
>> But your ingredient model, at least, should HABTM Recipe.
>> Ingredient
>> var $hasAndBelongsToMany = array('Recipe');
>>
>> And the join table should be ingredients_recipes.
>>
>>
>>
>> >
>>
>
>
>
> >
>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Relationships - HABTM

2009-01-19 Thread brian

That depends on what $this->Recipe->recursive is set to.

On Mon, Jan 19, 2009 at 4:34 PM, Steven Wright  wrote:
>
> Hi Brian one more thing for clarification. My expectation is that if I
> define the relationships correctly and my DB table are keyed correctly when
> I call for a read all from the Recipe model I should all related information
> from all tables no matter how deep the relationship. Is that correct?
>
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
> Of brian
> Sent: Monday, January 19, 2009 1:13 PM
> To: cake-php@googlegroups.com
> Subject: Re: Relationships - HABTM
>
>
> Both Recipe and Ingredient should be HABTM with each other. You can have
> many recipes which share ingredients. The join table for both would be:
>
> ingredients_recipes
> ingredient_id,
> recipe_id
>
> You could add an id primary key in there, also, as it might come in handy.
> It's not required, though.
>
> As for IngredientList, I'm not sure I've never thought much about doing this
> with Cake. I guess you could put the amount info, etc. in the
> ingredients_recipes join table but I'm not sure that'd be the best way.
>
> On Mon, Jan 19, 2009 at 12:50 PM, Steven Wright 
> wrote:
>>
>> Hi Brian thanks for writing back.
>>
>> The ingredient_lists table is where the ingredient, amount and
>> ingredient level instructions are stored. I suppose it's really a join
>> table for recipes, ingredients and measurement_types. So from your
>> reply I should actually rename this to ingredients_recipes.
>>
>> And you are saying that the Ingredient model gets the HABTM instead of
>> Recipe. Is that correct?
>>
>>
>>
>>
>> -----Original Message-
>> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On
>> Behalf Of brian
>> Sent: Monday, January 19, 2009 12:26 PM
>> To: cake-php@googlegroups.com
>> Subject: Re: Relationships - HABTM
>>
>>
>> On Mon, Jan 19, 2009 at 10:57 AM, rhythmicde...@gmail.com
>>  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 don't understand what you're doing with the ingredient_lists table.
>> But your ingredient model, at least, should HABTM Recipe.
>> Ingredient
>> var $hasAndBelongsToMany = array('Recipe');
>>
>> And the join table should be ingredients_recipes.
>>
>>
>>
>> >
>>
>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



RE: Relationships - HABTM

2009-01-19 Thread Steven Wright

Hi Brian one more thing for clarification. My expectation is that if I
define the relationships correctly and my DB table are keyed correctly when
I call for a read all from the Recipe model I should all related information
from all tables no matter how deep the relationship. Is that correct?


  

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of brian
Sent: Monday, January 19, 2009 1:13 PM
To: cake-php@googlegroups.com
Subject: Re: Relationships - HABTM


Both Recipe and Ingredient should be HABTM with each other. You can have
many recipes which share ingredients. The join table for both would be:

ingredients_recipes
ingredient_id,
recipe_id

You could add an id primary key in there, also, as it might come in handy.
It's not required, though.

As for IngredientList, I'm not sure I've never thought much about doing this
with Cake. I guess you could put the amount info, etc. in the
ingredients_recipes join table but I'm not sure that'd be the best way.

On Mon, Jan 19, 2009 at 12:50 PM, Steven Wright 
wrote:
>
> Hi Brian thanks for writing back.
>
> The ingredient_lists table is where the ingredient, amount and 
> ingredient level instructions are stored. I suppose it's really a join 
> table for recipes, ingredients and measurement_types. So from your 
> reply I should actually rename this to ingredients_recipes.
>
> And you are saying that the Ingredient model gets the HABTM instead of 
> Recipe. Is that correct?
>
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On 
> Behalf Of brian
> Sent: Monday, January 19, 2009 12:26 PM
> To: cake-php@googlegroups.com
> Subject: Re: Relationships - HABTM
>
>
> On Mon, Jan 19, 2009 at 10:57 AM, rhythmicde...@gmail.com 
>  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 don't understand what you're doing with the ingredient_lists table.
> But your ingredient model, at least, should HABTM Recipe.
> Ingredient
> var $hasAndBelongsToMany = array('Recipe');
>
> And the join table should be ingredients_recipes.
>
>
>
> >
>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



RE: Relationships - HABTM

2009-01-19 Thread Steven Wright

Ok I get it. Thanks man I really appreciate your time.

Steve
 

-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of brian
Sent: Monday, January 19, 2009 1:13 PM
To: cake-php@googlegroups.com
Subject: Re: Relationships - HABTM


Both Recipe and Ingredient should be HABTM with each other. You can have
many recipes which share ingredients. The join table for both would be:

ingredients_recipes
ingredient_id,
recipe_id

You could add an id primary key in there, also, as it might come in handy.
It's not required, though.

As for IngredientList, I'm not sure I've never thought much about doing this
with Cake. I guess you could put the amount info, etc. in the
ingredients_recipes join table but I'm not sure that'd be the best way.

On Mon, Jan 19, 2009 at 12:50 PM, Steven Wright 
wrote:
>
> Hi Brian thanks for writing back.
>
> The ingredient_lists table is where the ingredient, amount and 
> ingredient level instructions are stored. I suppose it's really a join 
> table for recipes, ingredients and measurement_types. So from your 
> reply I should actually rename this to ingredients_recipes.
>
> And you are saying that the Ingredient model gets the HABTM instead of 
> Recipe. Is that correct?
>
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On 
> Behalf Of brian
> Sent: Monday, January 19, 2009 12:26 PM
> To: cake-php@googlegroups.com
> Subject: Re: Relationships - HABTM
>
>
> On Mon, Jan 19, 2009 at 10:57 AM, rhythmicde...@gmail.com 
>  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 don't understand what you're doing with the ingredient_lists table.
> But your ingredient model, at least, should HABTM Recipe.
> Ingredient
> var $hasAndBelongsToMany = array('Recipe');
>
> And the join table should be ingredients_recipes.
>
>
>
> >
>



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Relationships - HABTM

2009-01-19 Thread brian

Both Recipe and Ingredient should be HABTM with each other. You can
have many recipes which share ingredients. The join table for both
would be:

ingredients_recipes
ingredient_id,
recipe_id

You could add an id primary key in there, also, as it might come in
handy. It's not required, though.

As for IngredientList, I'm not sure I've never thought much about
doing this with Cake. I guess you could put the amount info, etc. in
the ingredients_recipes join table but I'm not sure that'd be the best
way.

On Mon, Jan 19, 2009 at 12:50 PM, Steven Wright  wrote:
>
> Hi Brian thanks for writing back.
>
> The ingredient_lists table is where the ingredient, amount and ingredient
> level instructions are stored. I suppose it's really a join table for
> recipes, ingredients and measurement_types. So from your reply I should
> actually rename this to ingredients_recipes.
>
> And you are saying that the Ingredient model gets the HABTM instead of
> Recipe. Is that correct?
>
>
>
>
> -Original Message-
> From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
> Of brian
> Sent: Monday, January 19, 2009 12:26 PM
> To: cake-php@googlegroups.com
> Subject: Re: Relationships - HABTM
>
>
> On Mon, Jan 19, 2009 at 10:57 AM, rhythmicde...@gmail.com
>  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 don't understand what you're doing with the ingredient_lists table.
> But your ingredient model, at least, should HABTM Recipe.
> Ingredient
> var $hasAndBelongsToMany = array('Recipe');
>
> And the join table should be ingredients_recipes.
>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



RE: Relationships - HABTM

2009-01-19 Thread Steven Wright

Hi Brian thanks for writing back.

The ingredient_lists table is where the ingredient, amount and ingredient
level instructions are stored. I suppose it's really a join table for
recipes, ingredients and measurement_types. So from your reply I should
actually rename this to ingredients_recipes.

And you are saying that the Ingredient model gets the HABTM instead of
Recipe. Is that correct?




-Original Message-
From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On Behalf
Of brian
Sent: Monday, January 19, 2009 12:26 PM
To: cake-php@googlegroups.com
Subject: Re: Relationships - HABTM


On Mon, Jan 19, 2009 at 10:57 AM, rhythmicde...@gmail.com
 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 don't understand what you're doing with the ingredient_lists table.
But your ingredient model, at least, should HABTM Recipe.
Ingredient
var $hasAndBelongsToMany = array('Recipe');

And the join table should be ingredients_recipes.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Relationships - HABTM

2009-01-19 Thread brian

On Mon, Jan 19, 2009 at 10:57 AM, rhythmicde...@gmail.com
 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 don't understand what you're doing with the ingredient_lists table.
But your ingredient model, at least, should HABTM Recipe.
Ingredient
var $hasAndBelongsToMany = array('Recipe');

And the join table should be ingredients_recipes.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---