My implementation:
Category HABTM Article and Article HABTM Category
Category HABTM Gallery and Gallery HABTM Category
Category HABTM Link and Link HABTM Category
Category HABTM Document and Document HABTM Category
...
Database table for joins:
CREATE TABLE IF NOT EXISTS `categories_models` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL,
`model` varchar(255) NOT NULL,
`model_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
class Category extends AppModel {
var $name = 'Category';
var $hasAndBelongsToMany = array(
'Article' => array(
'className' => 'Article',
'joinTable' => 'categories_models',
'foreignKey' => 'category_id',
'associationForeignKey' => 'model_id',
'unique' => true,
'conditions' => array('CategoriesModel.model' => 'Article'),
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
}
class Article extends AppModel {
var $name = 'Article';
var $hasAndBelongsToMany = array(
'Category' => array(
'className' => 'Category',
'joinTable' => 'categories_models',
'foreignKey' => 'model_id',
'associationForeignKey' => 'category_id',
'unique' => true,
'conditions' => array('CategoriesModel.model' => 'Article'),
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
}
Almost everything works fine after use bake command but after article
save in 'categories_models' table I haven't field 'model' set to
'Article' - but fields 'category_id' and 'model_id' are correct.
Does anybody have idea how to force model Article to set field
`categories_models.model` to 'Article' using save functionality (and
have an example for it)?
Of course i could use CategoriesModel model and in controller function
add separate data from form
but this is my last hope solution. I think that this may be done in
other way.
If someone knows cakephp solution and could help .. i will be
gratefull
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment