You can try something like

def delete_linked(query, table=table):
    ids = [t.id in db(query).select(db.table.id)]
    for field in table._referenced_by:
         db(field._table._id.belongs(ids)).delete()

db.table._before_delete.append(delete_linked)

but you will run into consistency problems. If there are too many records 
this may fail midway.

On Wednesday, 14 November 2012 19:07:02 UTC-6, Julian Sanchez wrote:
>
> Hi Everyone!!  Long time lurker & first time posting...
>
> I am working on a simple application that I intend to deploy in GAE.  I 
> have a few tables with fields that reference other tables which by default 
> enables the ondelete=CASCADE behavior.  This works fine when I run the app 
> locally using sqlite as the database.
> I believe GAE doesn't support cascading deletes natively. 
> I presume web2py doesn't support cascading deletes when running under GAE 
> because I don't see that happening.  When I delete a row (rendered through 
> SQLFORM.grid) only that row is deleted an all dependent tables remain 
> untouched.
>
> The problem I have is that I can't find a way for me to implement the 
> cascading behavior manually.  I added a 'ondelete=mydelete' event for the 
> SQLFORM.grid where I do the manual delete of the dependent tables and 
> commit in the database, but that doesn't seem to work either.  I searched 
> through this forum but didn't find any suggestions either.  Any suggestions 
> as to what could I do to solve this??  Do I have to stay away from 
> SQLFORM.grid to avoid this problem?
>
> Many Thanks!!
> Julian
>
> I am using web2py Version 2.2.1 (2012-10-21 16:57:04) stable on OS X 
> Mountain Lion and GoogleAppEngineLauncher version 1.7.3 (1.7.3.333)
>

-- 



Reply via email to