I have an application built with CakePHP 1.3 with a model structure as 
follows:
Tenant hasMany Records (dependent => true)
Tenant hasMany Invoices (dependent => true)

An Invoice can have a reference to a Record which I represent as
Invoices belongsTo Records
so that fetching an Invoice will fetch the associated Record (if there is 
one)

In the Records model I have a beforeDelete method which checks that no 
Invoice references this record before deleting it.

This all works fine.  The potential problem I am considering is if I delete 
a Tenant it will cascade to delete all Records and Invoices associated with 
it.  Since I don't control the order in which the related models will be 
deleted it would be possible that the Records would be cascaded first and 
fail the beforeDelete method because of existing Invoices that reference 
the record ultimately failing the entire delete operation.  However, since 
the entire tenant is being deleted I do not want to enforce the constraint 
of not deleting a record if an invoice references it allowing the delete to 
complete regardless of the order that the associated models are deleted.

My questions are:
1. Do I have to worry about this?  I have not been able to produce the 
problem but it seems theoretically possible.
2. If I do have to worry about this scenario, is there a way to distinguish 
in the beforeDelete call whether this deleting is a direct deletion or a 
cascade from the Tenant deletion?  If I can do that then I would be able to 
add a condition to only enforce the constraint if this is a direct delete.
3. Is there a better way of representing this relationship that would not 
run into this problem?

Thanks

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to