Thanks Paul, that really helps. I like the approach with a model for the
link table as well. And since I do need to save extra data in the link
table, that's probably the way I'll need to do it.

But how should I set up the controllers for this? I'll need to access the
products and properties at the same time. I know I can probably create one
controller and access all three models at the same time using the $uses
variable. But if I understand it correctly, this is not the right approach.
But if I have 3 different controllers, how do I access products and
properties at the same time?

Thanks,
Plasty

On Sun, Apr 4, 2010 at 2:02 AM, WebbedIT <[email protected]> wrote:

> This seems like a pretty basic HABTM association.  If your join table
> (products_properties) is as simple as
>
> id
> product_id
> property_id
>
> then all you need to do is define your model associations as:
>
> Product:
> var $hasAndBelongsToMany = array(
>  'Property'
> );
>
> Property:
> var $hasAndBelongsToMany = array(
>  'Product'
> );
>
> Cake will automagically do the rest for you.  However if you want to
> store extra data in the join table then I find it much easier to
> create a model for the join table and create associations as follows:
>
> Product:
> var $hasMany = array(
>  'ProductsProperty'
> );
>
> Property:
> var $hasMany = array(
>  'ProductsProperty'
> );
>
> ProductsProperty:
> var $belongsTo = array(
>  'Product',
>  'Property'
> );
>
> This way you can run finds and saves on the join table saving extra
> data with ease, whereas HABTM associations are really only shortcuts
> to do this without creating the extra model and can complicate things.
>
> HTH
>
> Paul
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> 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]<cake-php%[email protected]>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to