(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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com 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.
No comments:
Post a Comment