Tuesday, February 19, 2013

Re: Only check beforeDelete if direct deletion


On Monday, February 18, 2013 12:27:46 AM UTC+2, cricket wrote:

Perhaps you need to re-think your schema. What is the purpose of Record?

Also, why do you wish to cancel a Record delete if an Invoice exists?

I abstracted the specific problem domain in the hopes of not getting lost in the details.
A Record represents a Tenant call with a bunch of associated data.  If an Invoice references a Record then the requirements of the system are that the view on Invoice needs to be able to display the information from the Record.  In addition, the business logic for handling an invoice needs to handle cases of Invoices with a Record (using some of the data from the Record) and Invoices without a record.  If a Record is deleted that is referenced by an Invoice then the data integrity is broken.

Rather than get into the specifics of the problem domain I am more interested in the CakePHP issues.

From reading through the CakePHP code it seems like calling delete on the top level model will call deleteAll on a hasMany related model if "exclusive" is set in the relationship.  deleteAll has three parameters.  The third is $callbacks which is set to false by default.  Since deleteAll is called by the top level model with only one parameter that would mean that the call backs would not be called and the problem I described would not happen.  I don't know if that is the intention of the "exclusive" attribute as the documentation just says that it means deleteAll is called.  But it seems to address my issue.

--
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+unsubscribe@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.
 
 

No comments: