Hi all I'm having the same problem, i'm trying to return an ID after an 'update_or_insert', but I need the ID whether it inserts or updates to add as a forign key to a related table.
Does anyone have a work around, someone mentioned that you could just 'db(condition).select(table.id) after that.' but i don't quite get this, could someone please explain. On Friday, December 30, 2011 at 6:31:37 PM UTC+1, olivier wrote: > > The "insert" method returns the id of the inserted row. > The "update_or_insert" method returns the id of the inserted row, but > returns None in case of an update... > > Why is it so? > > I have a case in which I want to update_or_insert and then further > update the corresponding row (to track the status of a long running > process). > I would rather have the method to always output the id of the updated/ > inserted row... > Or is there any use-case you would like to discriminate between the > fact you inserted or update a row? > > What do you think? > > -Olivier > > > From dal.py (I added the proposed modification) > =========== > > def update_or_insert(self, key=DEFAULT, **values): > if key==DEFAULT: > record = self(**values) > else: > record = self(key) > if record: > record.update_record(**values) > newid = None #------> why not record['id'] ???? > else: > newid = self.insert(**values) > return newid -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.