Does this help? http://teknoid.wordpress.com/2008/09/24/saving-extra-fields-in-the-join-table-for-habtm-models/
Jeremy Burns [email protected] On 13 Apr 2010, at 05:23, cricket wrote: > On Apr 12, 11:40 pm, "iamcam (Cameron Perry)" > <[email protected]> wrote: >> I believe you have to break the automagic HABTM relationship into >> hasMany and belongsTo with an explicit model representing the join >> table - manually join your Event and Guest models to the EventGuest >> through those relationships. The issue is that any time HABTM >> relationships get updated, the rows in the join table will get re- >> written without your data. It's not as big of a pain as it might >> sound. > > I've already got: > > Event HABTM Guest > Event hasMany EventGuest > EventGuest belongsTo Event, Guest > Guest hasMany EventGuest > Guest HABTM Event ('with' => 'EventGuest') > > But I think the reason why the EventGuest data is ignored is that > there's no EventGuest.id in the array. I was assuming that, if there's > a 'with' param in the HABTM array, and *that* model's data is present > in the data array, Cake would save that, along with the FK's from the > joined models. > > Oh, well. I ended up doing: > > if (!empty($this->data)) > { > $event_id = $this->data['Event']['id']; > > if ($this->Event->EventGuest->Guest->save($this->data)) > { > $guest_id = $this->Event->EventGuest->Guest->getInsertID(); > > $event_guest_id = $this->Event->EventGuest->field( > 'id', > array( > 'EventGuest.event_id' => $event_id, > 'EventGuest.guest_id' => $guest_id > ) > ); > > $this->data['EventGuest']['id'] = $event_guest_id; > $this->data['EventGuest']['guest_id'] = $guest_id; > > $this->Event->EventGuest->save($this->data); > > 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 [email protected] > To unsubscribe from this group, send email to > [email protected] For more options, visit this group at > http://groups.google.com/group/cake-php?hl=en > > To unsubscribe, reply using "remove me" as the subject. 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
