Tuesday, November 24, 2009

Add hasMany record in beforeSave

Hi there,

I'm having some problems adding a hasMany instance to another model
in beforeSave, I'm wondering if I have the wrong end of the stick?

I have a model User which hasMany EmailMessage. I have this in the add
action of my controller:

$this->data['EmailMessage'][0] = array(
'email_queue_id' => 1,
'email_address' => 'toby@testing.com',
'send_date' => date ("Y-m-d H:i:s"),
'subject' => 'test subject',
'body' => 'test body');

$this->User->saveAll($this->data, array('validate' => 'first'));

This works as expected. I thought I could move the creation of the
EmailMessage to my beforeSave in the User model - I just copied the
first line to the end of my beforeSave, just before I return 'true'.
When I do this nothing is saved in the email_messages table - am I
doing something wrong, or have I misunderstood something?

Thanks,

Toby

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