Sunday, September 26, 2010

habtm saving: is my really simple solution fragile? using a model for habtm-table

hi everyone,

I found this habtm saving tutorial on the net and it wont work for me:
http://bakery.cakephp.org/articles/view/add-delete-habtm-behavior

it uses both models in the relation and combines them to save or
delete data in the habtm-relation. now I had Problems with habtmAdd
and habtmDelete. some weird things happen...

So instead i did it my own way and created a model for my habtm-
relation:

class ProductsCategories extends AppModel
{

var $name = ProductsCategories';
var $useTable = 'products_categories';

}

so everytime a user hits the "save" button to save a relation i do
this really simple code using my newly created model

$this->data['ProductsCategories']['user_id']= $user_id;
$this->data['ProductsCategories']['product_id']= $pr_id;
$this->data['ProductsCategories']['visible']= "-1";
$saved = $this->ProductsCategories->save($this->data);

... instead of the more complex one from the tutorial. and it seems to
work. now the big question..

What is wrong with my code? I am using 1.3. is this not stable?
insecure?`will my pc explode? ;)
I dont trust my "skills" here.....it just seems too easy...

i am really curios here :) thanks a lot

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

No comments: