Friday, January 2, 2009

Re: saving to multiple models in a habtm relationship

A) thanks for the responses.

B) looking back I have a very poorly written post. What I meant to
say is that I want to save a new measure and a <em>new</em> article
all at once. So on the measure add page I also have all the fields
for adding both a new Measure and a new Article, which I want to be
associated through the articles_measures join table (side note: the
reason I'm trying to bind it to the "ArticlesMeasure" Model is because
that is how they do it at the bottom of this page of the cookbook
(http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM), but I
don't know why they do it that way).

What I'm trying to do in the Measure controller is to create a new
Measure, grab the id from that new measure, stick it into the data
array, then create a new Article & pass in the data array (which also
now has a new measure with an id#). From what I've read on blog posts
& various posts in this group, what I'm hoping will happen is that the
information saved to the Article Model, because it has an associated
model with an id number in the data array, is that it will update the
join table. Does this trick simply not work & there is a right way to
create two new records at the same time that have an HABTM
relationship, or is this what I'm supposed to do, but just not right?

Also, in the Measure/add view, the form fields for the new Article are
written like this
echo $form->input('Article.0.title');
is this part of my problem? Is this the correct way to name these
forms when trying to do something like this?

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