Friday, September 25, 2009

Re: Specific HABTM relation

I've found solution with binding models on the fly:

articles_controller function add (and function edit)
...
foreach($this->data['Category']['Category'] as $num => $category){
$this->data['CategoriesModel'][$num]['model_id'] = $this->data
['Article']['id'];
$this->data['CategoriesModel'][$num]['category_id'] = $category;
$this->data['CategoriesModel'][$num]['model'] = 'Article';
}
unset($this->data['Category']);
$this->Article->bindModel(array('hasMany'=>array('CategoriesModel')));

if ($this->Article->saveAll($this->data)) {
...

This is well known problem (i thought that only I have complicated
habtm relations) and was described here:
http://teknoid.wordpress.com/2008/09/24/saving-extra-fields-in-the-join-table-for-habtm-models/


--~--~---------~--~----~------------~-------~--~----~
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: