<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Derilicious&#187; Posts tagged with SoftDeletableBehavior &#8211; Page  &#8211; Derilicious</title> <atom:link href="http://derickng.com/posts/tag/softdeletablebehavior/feed" rel="self" type="application/rss+xml" /><link>http://derickng.com</link> <description>A blog on web development technicalities by Derick Ng</description> <lastBuildDate>Sun, 20 Dec 2009 12:18:03 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Soft Deletable Behavior and the Model::exists() gotcha</title><link>http://derickng.com/posts/31-soft-deletable-behavior-and-the-modelexists-gotcha</link> <comments>http://derickng.com/posts/31-soft-deletable-behavior-and-the-modelexists-gotcha#comments</comments> <pubDate>Sat, 15 Nov 2008 03:30:00 +0000</pubDate> <dc:creator>Derick Ng</dc:creator> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[CakePHP]]></category> <category><![CDATA[Model]]></category> <category><![CDATA[SoftDeletableBehavior]]></category><guid
isPermaLink="false">http://derick.lyniq.com/?p=31</guid> <description><![CDATA[If you ever used the Soft Deletable Behavior, you will realise that Model::del() always returns a FALSE. This is expected after knowing that the behavior intercepts the delete request by saving the deleted flag and date then returning FALSE so the actual delete don&#8217;t happen.
So since I can&#8217;t rely on the returned value of Model::del(), [...]]]></description> <content:encoded><![CDATA[<p>If you ever used the Soft Deletable Behavior, you will realise that <code>Model::del()</code> always returns a <code>FALSE</code>. This is expected after knowing that the behavior intercepts the delete request by saving the deleted flag and date then returning <code>FALSE </code>so the actual delete don&#8217;t happen.</p><p>So since I can&#8217;t rely on the returned value of <code>Model::del()</code>, this is what I thought will work until one fine day the application returns a failure when the record seems to be soft deleted correctly.</p><pre class="brush: php">

// some action of a controller
$this-&gt;Model-&gt;id = (int) $idPassed;
$this-&gt;Model-&gt;del();

if ($this-&gt;Model-&gt;exists()) {
    // say success!
} else {
    // say failure!
}
</pre><p>Alas, <code>Model::exists()</code> sets callbacks to <code>FALSE</code> in its <code>find('count')</code> call. So this means no <code>beforeFind</code> nor <code>afterFind</code> callbacks gets executed. This is understandable since Model uses <code>exists()</code> in many places where it needs to reflect true existence. So to get the expected results, we have to set callbacks to <code>TRUE</code> instead.</p><pre class="brush: php">

$this-&gt;exists(array(&#039;callbacks&#039; =&gt; true));
</pre>]]></content:encoded> <wfw:commentRss>http://derickng.com/posts/31-soft-deletable-behavior-and-the-modelexists-gotcha/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 6/13 queries in 0.009 seconds using disk

Served from: derickng.com @ 2010-08-01 04:21:25 -->