You can't have an Event.user_id if there's no User. You're doing this backwards.
On Sat, Jan 17, 2009 at 5:43 PM, mike <[email protected]> wrote: > > The user does not already exist. The event is being created, then > immediately after the user is being created. > > I forgot to mention, it occured to me to save the user first, then the > event, but its just for this specific application we decided to do it > this way. > > So how do I set the value of the hidden field Event.user_id to > User.id? that is what I'm not understanding. any examples? > > thanks! > > On Jan 17, 12:48 am, brian <[email protected]> wrote: >> Does the User already exist? Or, is the User being created at the same >> time as the event? >> >> Either way, if you create the event with the Event controller, all you >> need to do is make sure there's a hidden field for Event.user_id and >> that its value is set to the User.id. >> >> >> >> On Fri, Jan 16, 2009 at 11:45 PM, mike <[email protected]> wrote: >> >> > I'm not sure I understand this. How would the user controller know >> > which event its supposed to be related to? >> >> > I have the user model set to hasMany Events, and Event belongsTo >> > User. In the view I have the hidden field as suggested. >> >> > then I tried this: >> > $this->data['Event']['user_id'] = >> > $this->User->getLastInsertId(); >> > $this->User->Event->save($this->data); >> >> > but this just adds a new row to the event table, instead of updating >> > the last inserted one. >> >> > On Jan 16, 10:43 pm, "Jon Bennett" <[email protected]> wrote: >> >> > However, wouldn't it make more sense to submit the User info before >> >> > the Event info? I assume that a User hasMany Event. In which case, >> >> > you'd have the User submit their info and ensure that >> >> > $this->data['User']['id'] was set before rendering (not redirect to) >> >> > the Event form view, which would have: >> >> >> > echo $form->hidden('User.id'); >> >> >> If this is going in a form tied to the Event model, shouldn't it in fact >> >> be: >> >> >> // hidden form input for foreign key in events table >> >> echo $form->hidden('Event.user_id'); >> >> >> hth >> >> >> jon >> >> >> -- >> >> >> jon bennett >> >> w:http://www.jben.net/ >> >> iChat (AIM): jbendotnet Skype: jon-bennett- Hide quoted text - >> >> - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
