On Wednesday, 16 November 2011 15:24:14 UTC+1, RhythmicDevil wrote:
>
> I am writing a custom datasource. I was implementing the delete action 
> in the datasource and ran into a problem. I expected that when I call 
> Model::delete($id, false); it would execute the Datasource::delete() 
> method. But that does not happen. First a method called calculate() is 
> executed and then Datasource::read() is executed. I dont know why.  


> 1. So why does the calculate() method get called and how do I prevent 
> that as it makes no sense my implementation. 
>

calculate is called to determine the syntax for a count.
 

>
> 2. Why does the read() method get called before delete() and how do I 
> prevent that?
>

That's executing the count
 

>
> 3. Is there a document somewhere that lists the methods called in 
> order of execution for CRUD operations?



There's no better source of info than the code itself: 
https://github.com/cakephp/cakephp/blob/master/lib/Cake/Model/Model.php#L2183

the short answer to your question is the model does if (!this->exists()) { 
return false } before performing the delete, exists() simply performs a 
find count and you're focussing on the queries that generates.

If you want to skip that, you could rig exists (in the datasource) to 
always return true - may cause you other problems that way though. Of use 
deleteAll with no cascade and no callbacks.

I guess it would be handy if the model allowed for skipping the exists 
checks - but it doesn't.

AD

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to