I know this has been asked before but I'm missing something here.

models: Event HABTM Guest
I need to save some extra fields in events_guests table. I've created
a join model, EventGuest:
$belongsTo = array('Event', 'Guest');

Guest:
var $hasAndBelongsToMany = array(
                'Event' => array('with' => 'EventGuest')
);
Event:
var $hasAndBelongsToMany = array(
                'Guest' => array('with' => 'EventGuest')
);

The data is coming in like:
array(
        'Event' => array(
                'id' => 12
        ),
        'Guest' => array(
                ...
        ),
        'EventGuest' => array(
                'event_id' => 12,
                ...
        )
);

Now, when I save Guest, Cake is also creating a record in
events_guests. Unfortunately, it's ignoring the EventGuest data. I had
the impression the 'with' param would take care otf that.

So, anyway, I thought I'd simply add the correct IDs to my data and re-
save EventGuest. Unfortunately again, getInsertID() returns nothing!
I'm assuming it's because it wasn't directly saved (and seems like a
bug).

if ($this->Event->EventGuest->Guest->save($this->data))
{
        $event_guest_id = $this->Event->EventGuest->getInsertID();
        $guest_id = $this->Event->EventGuest->Guest->getInsertID();

        $this->data['EventGuest']['id'] = $event_guest_id;
        $this->data['EventGuest']['guest_id'] = $guest_id;

        $this->Event->EventGuest->save($this->data);

So I end up with 2 records in events_guests. The first is missing the
extra data.

Now, I realise that I can instead use field() to retrieve
theEventGuest.id but is there simply something I've missed here?

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.

Reply via email to