I have a Message model that hasMany MessageRecipients. I have a form that 
posts data into a controller which passes it straight to a method in the 
Message model.

Three questions really...

1) How should the form be set up?
The MessageRecipient model expects two fields; message_id and user_id. When 
I create the form I add a control called 'MessageRecipient'. This just 
passes a keyed array of user ids. How can I make those sit in the user_id 
field? Naming the field MessageRecipient.user_id is not the answer.

2) Once the data array arrives at the model it is not in the same shape as 
that suggested by the book. The book suggests it should look like this:
$data = array(
    'Article' => array('title' => 'My first article'),
    'Comment' => array(
        array('body' => 'Comment 1', 'user_id' => 1),
        array('body' => 'Comment 2', 'user_id' => 12),
        array('body' => 'Comment 3', 'user_id' => 40),
    ),
);
... rather than:

array(
'Message' => array(
'subject' => '',
'content' => 'Test',
'user_id' => 1,
'MessageRecipient' => array(
(int) 0 => 2,
(int) 1 => 3
)
)
)

... as passed by the form. Do the numeric keys really matter? How do I get 
the array to be in this shape:

array(
'Message' => array(
'subject' => '',
'content' => 'Test',
'user_id' => 1,
'MessageRecipient' => array(
array ('user_id' => 2),
array ('user_id' => 3)
)
)
)

... without parsing the data?

3) After the data is saved using $this->saveAssociated() I'd expect the id 
of the new message to be in $this->id, yet it is always null. I can reach 
$this->MessageRecipient->id and 
$this->MessageRecipient->field('message_id') but that feels wrong. What's 
the recommended approach?

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to