Notice you can do user = db.users.insert(name="John") print user 1 print isinstance(user,int) True print user.name "John"
magic! On Mar 30, 12:18 pm, Thadeus Burgess <[email protected]> wrote: > user_id = db.users.insert(.....) > contact = db.contacts.insert(user = user_id, user_recording='/hi/'....) > > So insert returns the id of the newly inserted record.. > > If you want the actual object of what you just inserted you need > > user = db.user[db.users.insert(...)] > > Now you can perform, user.update/user.update_record() etc etc. > > -Thadeus > > On Tue, Mar 30, 2010 at 12:09 PM, compassiontara <[email protected]> wrote: > > Perhaps I'm missing the obvious, but I can't figure out how to make > > this work: > > > db.define_table('users', > > Field('phone','string',unique=True), > > Field('safe','boolean',default=False), > > Field('allow_le','boolean',default=False), > > Field('safe_time','datetime'), > > Field('finished','boolean'), > > Field('finished_time','datetime'), > > Field('start_time','datetime'), > > ) > > db.define_table('contacts', > > Field('user',db.users), > > Field('phone','string'), > > Field('user_recording','string'), > > Field('called','boolean',default=False), > > ) > > > db.users.insert(phone='17125551212',safe_time=datetime.datetime.now() > > +3600) > > db.contacts.insert(user=user_id,user_recording='/var/sounds/ > > blah.wav',phone='15555551212') > > > where the db.contacts insert needs the .id from the db.users.insert. > > I want both to be within a transaction, but because web2py does > > transactions and commits automatically at end, how would I make this > > happen? > > > I understand I could do something insane like commit(), do a query to > > get the new ID record, and then do the insert for contacts, and then > > if that fails, go delete the record from users, but I'm hoping that > > there is a more humane way of doing this? > > > With Love, > > Tara > > > -- > > You received this message because you are subscribed to the Google Groups > > "web2py-users" 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 > > athttp://groups.google.com/group/web2py?hl=en. -- You received this message because you are subscribed to the Google Groups "web2py-users" 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/web2py?hl=en.

