PDA

View Full Version : Save a new object and its associations together



thachun
29 Mar 2012, 2:29 AM
Hi all,

I have a User model and a Post model. They have a one-many relationship. So now, I would like to save a new User object and all of its Posts to the server. Please tell me how to do that. Thank so much!

Cheers,
Thach

mitchellsimoens
29 Mar 2012, 7:44 AM
When you save a model, it's associated data is not part of the model so it's not sent.

börn
29 Mar 2012, 8:23 AM
Yap.. unfortunately... You can get the associated data with getAssociatedData and set that to the model instance aka record you want to save.

ykey
11 Apr 2012, 9:02 AM
If I can load nested Model data (through associations) in one shot, why can't I persist it that way?