Hello, But how to implement db foreign key constraint at web2py model level??
Thank you. Richard On Thu, Nov 18, 2010 at 2:41 PM, mdipierro <[email protected]> wrote: > good point. > > This will work: > > if request.post_vars.delete_this_record: > del request.post_vars.delete_this_record > db.t_person.active.update=False > > there are two problems in your example: > - you are using request.vars and not request.post_vars which crud uses > and therefore the variable is not deleted > - web2py actually deletes the record but that breaks the references, > the db raises an exception, web2py catches it and rollsback, so the > record is still there. > > Massimo > > On Nov 18, 1:14 pm, Carlos <[email protected]> wrote: > > Hi, > > > > I'm trying to replace the built-in delete behavior in crud.update > > (deletable=True) with a boolean active field instead, in order to NOT > > do a hard-delete of any records but instead a soft-delete via the > > active flag. > > > > I'm also using onaccept=crud.archive. > > > > I successfully manage to cancel the delete operation (currently in all > > cases for testing purposes) via the following just before the > > crud.update: > > > > if request.vars: del request.vars.delete_this_record > > > > But when the crud.update is executed (with crud.archive) and the > > delete checkbox is on, I get the following error: > > > > <class 'psycopg2.IntegrityError'>(insert or update on table > > "entity_archive" violates foreign key constraint > > "entity_archive_current_record_fkey" > > DETAIL: Key (current_record)=(6) is not present in table "entity".) > > > > Note that the record is NOT deleted (as expected), and therefore I > > don't understand why crud.archive is complaining about it. > > > > Also note that crud.update (with crud.archive) works ok when the > > delete checkbox is off. > > > > I've checked request.vars and I don't see any problems. > > > > Can you please help?. > > > > Thanks, > > > > Carlos >

