Thanks Anthony, I think you're right,
solution should be that after check 
    ondelete='CASCADE' and 
    check autodelete=True, 
default _before_delete erase the associated files in uploads folder.

I posted an issue on Google Gode (n.1854).

Maurizio


Il giorno mercoledì 15 gennaio 2014 15:39:07 UTC+1, Anthony ha scritto:
>
> The cascading delete is handled by the database, so the web2py DAL is not 
> executing the delete from the db.allegato table and therefore doesn't have 
> the opportunity to run the _before_delete and _after_delete callbacks (the 
> former is used to autodelete uploaded files).
>
> I suppose you could create a _before_delete callback on the db.prodotto 
> table that does the file deleting. Maybe we could build this in to the 
> default _before_delete callbacks for tables -- it would check the 
> _referenced_by fields for ondelete='CASCADE', then check the referring 
> table for upload fields with autodelete=True, and then delete the 
> associated files (or maybe just run the _before_delete callback of the 
> referring table). You can post an issue on Google Code and reference this 
> thread.
>
> In the documentation, we should probably note that the _before_delete and 
> _after_delete callbacks of a table will not be run when the delete happens 
> in the database as the result of a cascade.
>
> Anthony
>
> On Wednesday, January 15, 2014 4:26:47 AM UTC-5, maurizio wrote:
>>
>> Hi all,
>> probably due to my incompetence I have the following problem,
>> Thank's in advance anyone who wants to help me.
>>
>> consider the following code:
>>
>> '''
>> db.define_table('prodotto',
>>         Field('nome'),
>>         format='%(nome)s',
>>         plural='prodotti')
>>
>> db.define_table('allegato',
>>         Field('descrizione',requires=IS_NOT_EMPTY()),
>>         Field('documento','upload',autodelete=True),
>>         Field('prodotto','reference 
>> prodotto',writable=False,readable=False),
>>         format='%(descrizione)s',
>>         plural='allegati')
>>
>> def index():
>>     grid = SQLFORM.smartgrid(db.prodotto,
>>                         deletable=True,
>>                         editable=True,
>>                         create=True,
>>                         csv=False)
>>     return dict(grid=grid)
>>
>> web2py 2.7.4-stable+timestamp.2013.10.14.15.16.29
>> (Running on Rocket 1.2.6, Python 2.7.3) Debian  7.2 (wheezy)
>> '''
>>
>> Deleting a record from the "allegato" table, also delete the 
>> corresponding file (autodelete=True) in the default /uploads folder.
>> Deleting a record from the "prodotto" master table, also delete all 
>> records in the "allegato" detail table (CASCADE delete), but files in the 
>> folder uploads are not erased.
>>
>> Any idea?
>>
>> thanks again
>> Maurizio
>>
>

-- 
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.

Reply via email to