question about db.files._before_delete.append()

13 views
Skip to first unread message

António Ramos

unread,
Aug 26, 2016, 7:37:56 AM8/26/16
to web...@googlegroups.com
Hello 
i have 3 tables entities, files and events.
Files table has a _before_delete callback to delete all events of a file in table events before deleting the file.
table events is to drop events for files and entities so i did not create a foreign key but instead created in entities and files tables  a uuid field and in table events a field relatedto where i will save the uuid of the entity or the file ( is this a good way?)
anyway...
when i delete a file it correctly deletes the events for that file , BUT!!!
i was not expecting that deleting a record in table entities also triggers the files callback and the callback received the id of the entities deleted

any suggestion?


*******************************************************
db.define_table(
    'entities',
    Field('uuid',length=64,default=lambda:str(uuid.uuid4())),
    ...
)
*********************************************************
b.define_table(
    'files',
    ...
    Field('uuid',length=64,default=lambda:str(uuid.uuid4())),
    Field('entities',db.entities),
 ...
)
def delete_ev(*args): 
    uuid=db.ficheiros[args[0].query.second]["uuid"]
    db(db.events.relatedto==uuid).delete()

db.files._before_delete.append(lambda s:delete_ev(s))

**************************************************************
db.define_table(
    'events',
    ....
    Field('relatedto'),

)



Reply all
Reply to author
Forward
0 new messages