<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: The Model::validates() trap</title>
	<atom:link href="http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Thu, 11 Mar 2010 15:41:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: rafaelbandeira3</title>
		<link>http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/comment-page-1/#comment-112176</link>
		<dc:creator>rafaelbandeira3</dc:creator>
		<pubDate>Fri, 07 Nov 2008 16:08:21 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=928#comment-112176</guid>
		<description>@cakebaker: yes, but actually, save is not part of the ActiveRecord pattern, it belongs to the Mapper - wich is another role in the Model layer that is played by the Model class on cake - as update, and delete. The last one is the cranky one, that on cake acts on the record, that, although doesn&#039;t feet the &quot;pattern&quot;, is much more logical.
But as you say &quot;you can see it in that way&quot;. It&#039;s not a rule.</description>
		<content:encoded><![CDATA[<p>@cakebaker: yes, but actually, save is not part of the ActiveRecord pattern, it belongs to the Mapper &#8211; wich is another role in the Model layer that is played by the Model class on cake &#8211; as update, and delete. The last one is the cranky one, that on cake acts on the record, that, although doesn&#8217;t feet the &#8220;pattern&#8221;, is much more logical.<br />
But as you say &#8220;you can see it in that way&#8221;. It&#8217;s not a rule.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/comment-page-1/#comment-112174</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 07 Nov 2008 16:01:47 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=928#comment-112174</guid>
		<description>@all: Thanks for your comments!

@joe: Yes, somehow it feels just natural to pass the data directly to the validates() method.

@Phally: Yes, that&#039;s an alternative to create(), thanks for mentioning it.

@Rafael: Yes, you can see it in that way. Unfortunately, the implementation doesn&#039;t follow this principle strictly. Compare the methods validates() and save(): validates() doesn&#039;t have a $data parameter whereas save() has such a parameter...</description>
		<content:encoded><![CDATA[<p>@all: Thanks for your comments!</p>
<p>@joe: Yes, somehow it feels just natural to pass the data directly to the validates() method.</p>
<p>@Phally: Yes, that&#8217;s an alternative to create(), thanks for mentioning it.</p>
<p>@Rafael: Yes, you can see it in that way. Unfortunately, the implementation doesn&#8217;t follow this principle strictly. Compare the methods validates() and save(): validates() doesn&#8217;t have a $data parameter whereas save() has such a parameter&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rafaelbandeira3</title>
		<link>http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/comment-page-1/#comment-112013</link>
		<dc:creator>rafaelbandeira3</dc:creator>
		<pubDate>Wed, 05 Nov 2008 14:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=928#comment-112013</guid>
		<description>On thing one should be aware when dealing with models is that the Model class represents almost the whole Model layer in cake&#039;s MVC - the (Active)Record and the Finder - so every method that is not related to the finder scope is applied directly to the current record that the model is representing, if any, or the data and state of a incoming record.
So Model::validate() is supposed to validate the current record/state data, and that&#039;s why it should receive only $options as parameters, and no data.
And that&#039;s why the idea of keeping find methods on Model::find() and so on... to make a little separation, between the Finder and the Record.
In my implementations, every custom public method is only appliable to the Record concept or to the class itself - defining params and options.
That&#039;s why I&#039;m a &quot;http://cakebaker.42dh.com/2008/09/23/an-alternative-way-to-define-custom-find-types/&quot; Evangelist.</description>
		<content:encoded><![CDATA[<p>On thing one should be aware when dealing with models is that the Model class represents almost the whole Model layer in cake&#8217;s MVC &#8211; the (Active)Record and the Finder &#8211; so every method that is not related to the finder scope is applied directly to the current record that the model is representing, if any, or the data and state of a incoming record.<br />
So Model::validate() is supposed to validate the current record/state data, and that&#8217;s why it should receive only $options as parameters, and no data.<br />
And that&#8217;s why the idea of keeping find methods on Model::find() and so on&#8230; to make a little separation, between the Finder and the Record.<br />
In my implementations, every custom public method is only appliable to the Record concept or to the class itself &#8211; defining params and options.<br />
That&#8217;s why I&#8217;m a &#8220;http://cakebaker.42dh.com/2008/09/23/an-alternative-way-to-define-custom-find-types/&#8221; Evangelist.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phally</title>
		<link>http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/comment-page-1/#comment-112010</link>
		<dc:creator>Phally</dc:creator>
		<pubDate>Wed, 05 Nov 2008 13:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=928#comment-112010</guid>
		<description>You can also use set() for that. Like this:
&lt;code&gt;
public function example() {
    $data = array(&#039;Project&#039; =&gt; array(&#039;name&#039; =&gt; &#039;Testproject&#039;));
    $this-&gt;Project-&gt;set($data);
    if ($this-&gt;Project-&gt;validates()) {
        echo &#039;valid&#039;;
    } else {
        echo &#039;invalid&#039;;
    }
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>You can also use set() for that. Like this:<br />
<pre><code>public function example() {
    $data = array('Project' =&gt; array('name' =&gt; 'Testproject'));
    $this-&gt;Project-&gt;set($data);
    if ($this-&gt;Project-&gt;validates()) {
        echo 'valid';
    } else {
        echo 'invalid';
    }
}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: joe siao</title>
		<link>http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/comment-page-1/#comment-112005</link>
		<dc:creator>joe siao</dc:creator>
		<pubDate>Wed, 05 Nov 2008 11:28:36 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/?p=928#comment-112005</guid>
		<description>Hi,

I also make mistakes like you when using that function. Can&#039;t get it used to my system yet.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I also make mistakes like you when using that function. Can&#8217;t get it used to my system yet.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
