Sunday, October 26, 2008

Re: not understanding simple HABTM save/delete

After hours and hours of frustration, I've figured it out. It wasn't fun, but
maybe not having my questions answered makes me a better programmer. For
future reference, it's actually pretty simple. I started with a new app with
my existing models and by baking new controllers/views I was able to figure
it out:

Since I'm applying a 'Label' to an 'Item', I just save() to my 'Item' model:

$this->Item->save($data);

And pr($data) looks like this:

Array
(
[Item] => Array
(
[id] => 1
)
[Label] => Array
(
[Label] => Array
(
[0] => 4
[1] => 5
[2] => 7
[3] => 8
)
)
)

I also found that delete() isn't necessary. Before the new
associations/records are inserted in 'items_labels' for a given 'item_id'
(in the case, it's 1), all of the existing records for that 'item_id' are
deleted.
--
View this message in context: http://n2.nabble.com/not-understanding-simple-HABTM-save-delete-tp1377073p1380365.html
Sent from the CakePHP mailing list archive at Nabble.com.


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