Apologies - message sent prematurely.
On 20 December 2013 15:18, Johann Spies <johann.sp...@gmail.com> wrote: > I have never used after_insert or before_insert before and the > documentation in the book does not answer enough of my questions. > > > Having the following models I want to create an invoice and record some of > its particulars in the invoice table and then link the transactions that > were invoiced to the invoice number: > > db.define_table('invoice', > Field('invoice_date', 'date', > requires=IS_NOT_EMPTY()), > Field('client', 'reference client', > requires=IS_NOT_EMPTY(), > represent = lambda value, row: A('{}'.format( > row.client.name), > > _href=URL('show_client', args=value))), > Field('from_date', 'date'), > Field('to_date', 'date')) > > db.define_table('transactions', > Field('client', 'reference client', > represent = lambda value, row: A('{}'.format( > row.client.name), > _href=URL('show_client', > args=value))), > ... > Field('invoice', 'reference invoice')) > > > The invoice will be created using the client, from_date and to_date particulars making a summary of what is going on the transactions-table which also has a transaction_date field not shown above. I want to ensure that the invoice record gets inserted and then all the transactions updated with the invoice-id in a way that if the latter process fails the transaction will be aborted and the invoice record deleted from the table. Can i use after_insert for this or is it better to use the database's transaction capabilities through db.executesql? Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) -- 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/groups/opt_out.