<?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: Fat models and how they change how you use the Model class</title>
	<atom:link href="http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Wed, 10 Mar 2010 21:27:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: CakePHP コントローラに処理を書かずにモデルにメソッドを追加しよう！ &#124; Sun Limited Mt.</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-79005</link>
		<dc:creator>CakePHP コントローラに処理を書かずにモデルにメソッドを追加しよう！ &#124; Sun Limited Mt.</dc:creator>
		<pubDate>Mon, 31 Mar 2008 07:29:23 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-79005</guid>
		<description>[...] CakePHP だけではなくフレームワーク全般に当てはまることだと思います。 Fat models and how they change how you use the Model class - cakebaker [...]</description>
		<content:encoded><![CDATA[<p>[...] CakePHP だけではなくフレームワーク全般に当てはまることだと思います。 Fat models and how they change how you use the Model class &#8211; cakebaker [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abba Bryant</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-60163</link>
		<dc:creator>Abba Bryant</dc:creator>
		<pubDate>Sat, 26 Jan 2008 23:12:27 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-60163</guid>
		<description>My general rule for whether or not to place the logic in a callback is whether or not I am working with models referenced through ( or creating on the fly ) relationships in the current model.

If the answer is no, or it is such that I need to make use of a model loaded through the Controller&#039;s uses array then I place the logic in the controller. The cutoff point for me is that if I ever would need to App::import a model into another model then I should be moving the logic to a controller.


@Tim Daldini I generally write my custom model functions to accept the same options array as the internal function I would be using anyways ( the array passed to find, read, etc ) and simply set the defaults I generally need in the function declaration. Then you can simply call it for the default common needs, or pass an options array in. Depending on your needs sometimes processing the options is more code than fetching, tweaking and returning the data but it does leave things flexible.</description>
		<content:encoded><![CDATA[<p>My general rule for whether or not to place the logic in a callback is whether or not I am working with models referenced through ( or creating on the fly ) relationships in the current model.</p>
<p>If the answer is no, or it is such that I need to make use of a model loaded through the Controller&#8217;s uses array then I place the logic in the controller. The cutoff point for me is that if I ever would need to App::import a model into another model then I should be moving the logic to a controller.</p>
<p>@Tim Daldini I generally write my custom model functions to accept the same options array as the internal function I would be using anyways ( the array passed to find, read, etc ) and simply set the defaults I generally need in the function declaration. Then you can simply call it for the default common needs, or pass an options array in. Depending on your needs sometimes processing the options is more code than fetching, tweaking and returning the data but it does leave things flexible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Golding Design Blog -</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-60112</link>
		<dc:creator>David Golding Design Blog -</dc:creator>
		<pubDate>Sat, 26 Jan 2008 17:14:15 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-60112</guid>
		<description>[...] took Daniel Hofstetter&#8217;s advice to look for opportunities to put functions in the model rather than in the controller. Not only did [...]</description>
		<content:encoded><![CDATA[<p>[...] took Daniel Hofstetter&#8217;s advice to look for opportunities to put functions in the model rather than in the controller. Not only did [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-60039</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Sat, 26 Jan 2008 09:26:55 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-60039</guid>
		<description>@Tim: Good point. Adding optional parameters to the method is one possible solution. Another solution could be to write separate methods for the special cases. But as so often in software development there is no best solution...

Yes, it is difficult to foresee how an application will change over time. So you always have to write code that&#039;s clean and easy to change (I know, it is easier said than done, and unfortunately you often learn only at the time when you have to make a change that your solution wasn&#039;t that good...).

@Abba: Ah, yes, that&#039;s a better example. And it&#039;s true that there is not much talk about callbacks. I guess it is because they aren&#039;t used often. If I look at my own code, the only callback I often use is Controller::beforeFilter(), I almost never use the other callbacks.

@Stephen: Strange, sounds like a bug to me. Maybe it helps as a workaround to manually instantiate your model like $this&gt;Product = new Product(); ?</description>
		<content:encoded><![CDATA[<p>@Tim: Good point. Adding optional parameters to the method is one possible solution. Another solution could be to write separate methods for the special cases. But as so often in software development there is no best solution&#8230;</p>
<p>Yes, it is difficult to foresee how an application will change over time. So you always have to write code that&#8217;s clean and easy to change (I know, it is easier said than done, and unfortunately you often learn only at the time when you have to make a change that your solution wasn&#8217;t that good&#8230;).</p>
<p>@Abba: Ah, yes, that&#8217;s a better example. And it&#8217;s true that there is not much talk about callbacks. I guess it is because they aren&#8217;t used often. If I look at my own code, the only callback I often use is Controller::beforeFilter(), I almost never use the other callbacks.</p>
<p>@Stephen: Strange, sounds like a bug to me. Maybe it helps as a workaround to manually instantiate your model like $this&gt;Product = new Product(); ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Orr</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-59821</link>
		<dc:creator>Stephen Orr</dc:creator>
		<pubDate>Fri, 25 Jan 2008 13:02:48 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-59821</guid>
		<description>As a follow-up to my last comment, it looks like I was correct. Referring to calling functions within main app models from a plugin - it doesn&#039;t work.

I just proved this by creating a controller in my main application which calls the function. This works, instead of passing through to the SQL.</description>
		<content:encoded><![CDATA[<p>As a follow-up to my last comment, it looks like I was correct. Referring to calling functions within main app models from a plugin &#8211; it doesn&#8217;t work.</p>
<p>I just proved this by creating a controller in my main application which calls the function. This works, instead of passing through to the SQL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Orr</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-59817</link>
		<dc:creator>Stephen Orr</dc:creator>
		<pubDate>Fri, 25 Jan 2008 12:58:58 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-59817</guid>
		<description>I&#039;m having problems with this approach, and I&#039;d like to know if it&#039;s just me that&#039;s doing something wrong.

I have an ecommerce site built using Cake, and it&#039;s gotten to the point where I&#039;m fine-tuning the admin backend, which I&#039;ve built as a plugin.

I&#039;m trying to fatten up my models now to remove some of the complexity from my controllers - but I&#039;m unable to call any of the functions I&#039;m writing - the call just gets passed directly through to MySQL and so fails.

As an example, I&#039;m trying to do:
$this-&gt;Product-&gt;findMostPopular();

Instead of calling the Product::findMostPopular() method, it&#039;s directly executing findMostPopular as SQL.

Could this be because I&#039;m referring to main app models from my plugin?</description>
		<content:encoded><![CDATA[<p>I&#8217;m having problems with this approach, and I&#8217;d like to know if it&#8217;s just me that&#8217;s doing something wrong.</p>
<p>I have an ecommerce site built using Cake, and it&#8217;s gotten to the point where I&#8217;m fine-tuning the admin backend, which I&#8217;ve built as a plugin.</p>
<p>I&#8217;m trying to fatten up my models now to remove some of the complexity from my controllers &#8211; but I&#8217;m unable to call any of the functions I&#8217;m writing &#8211; the call just gets passed directly through to MySQL and so fails.</p>
<p>As an example, I&#8217;m trying to do:<br />
$this-&gt;Product-&gt;findMostPopular();</p>
<p>Instead of calling the Product::findMostPopular() method, it&#8217;s directly executing findMostPopular as SQL.</p>
<p>Could this be because I&#8217;m referring to main app models from my plugin?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abba Bryant</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-59665</link>
		<dc:creator>Abba Bryant</dc:creator>
		<pubDate>Thu, 24 Jan 2008 22:31:17 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-59665</guid>
		<description>Yeah the profile is a bad example. A better example is a node based cms - when creating a parent node there may be required child nodes of different types. These might depend on data in the submitted data array. In this case a bit of logic in the afterSave callback ( which ideally should then delegate to private function calls ) to associate the correct nodes with different types of parent nodes.

Bleh, my original point is that amidst all of this Fat Models discussion there has been very little posted on the usage of the controller / model callbacks system outside of the few behavior authors.</description>
		<content:encoded><![CDATA[<p>Yeah the profile is a bad example. A better example is a node based cms &#8211; when creating a parent node there may be required child nodes of different types. These might depend on data in the submitted data array. In this case a bit of logic in the afterSave callback ( which ideally should then delegate to private function calls ) to associate the correct nodes with different types of parent nodes.</p>
<p>Bleh, my original point is that amidst all of this Fat Models discussion there has been very little posted on the usage of the controller / model callbacks system outside of the few behavior authors.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Daldini</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-59653</link>
		<dc:creator>Tim Daldini</dc:creator>
		<pubDate>Thu, 24 Jan 2008 21:56:18 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-59653</guid>
		<description>I tried to do this but sometimes it creates &quot;dependencies&quot;. Suppose you need to call your findMostRecent 4 times in your application, possibly in different controllers.

Later you notice you need to change 2 of those calls. One should use an extra condition, and another should fetch different fields...what do you do in such case? You could add extra optional field and condition arguments but in the end I think it would make things possibly harder to read because you might customize several of model methods in different ways as you develop your application...and you sometimes need to remember why and how you changed things.

Because it is sometimes hard to foresee how your application will change (and also, I hate switching between multiple files...) I mostly don&#039;t use this technique. I personally think using standard model methods are very readable once you are familiar with them.

But I guess that&#039;s just me...</description>
		<content:encoded><![CDATA[<p>I tried to do this but sometimes it creates &#8220;dependencies&#8221;. Suppose you need to call your findMostRecent 4 times in your application, possibly in different controllers.</p>
<p>Later you notice you need to change 2 of those calls. One should use an extra condition, and another should fetch different fields&#8230;what do you do in such case? You could add extra optional field and condition arguments but in the end I think it would make things possibly harder to read because you might customize several of model methods in different ways as you develop your application&#8230;and you sometimes need to remember why and how you changed things.</p>
<p>Because it is sometimes hard to foresee how your application will change (and also, I hate switching between multiple files&#8230;) I mostly don&#8217;t use this technique. I personally think using standard model methods are very readable once you are familiar with them.</p>
<p>But I guess that&#8217;s just me&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-59603</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Thu, 24 Jan 2008 17:50:24 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-59603</guid>
		<description>@all: Thanks for your comments!

@Thomas, henrique: If you look at the design of the model class I doubt it was intended to be used in that way, at least it doesn&#039;t force you to write fat models.

@Kalileo: Yes, refactoring is always a good thing to do. When I refactor stuff I usually end up with some private methods, and the AppModels stay rather skinny. But this is probably application-specific.

@Yevgeny: Yes, that&#039;s true, model code is much easier to test than controller code.

@Dave: Yes, that&#039;s something you always have to ask yourself when writing code (not only when writing models). 

@Jelle: To me your scenario sounds like it would make sense to have special methods like saveAsDraft(), saveAsSent(), etc. But it could also make sense to create models for your states, it depends on your requirements.

@Abba: Hm, I wouldn&#039;t create the Profile in the afterSave() callback function.  I would rather create it at the place where the User is saved, so that you see those two &quot;actions&quot; are connected.</description>
		<content:encoded><![CDATA[<p>@all: Thanks for your comments!</p>
<p>@Thomas, henrique: If you look at the design of the model class I doubt it was intended to be used in that way, at least it doesn&#8217;t force you to write fat models.</p>
<p>@Kalileo: Yes, refactoring is always a good thing to do. When I refactor stuff I usually end up with some private methods, and the AppModels stay rather skinny. But this is probably application-specific.</p>
<p>@Yevgeny: Yes, that&#8217;s true, model code is much easier to test than controller code.</p>
<p>@Dave: Yes, that&#8217;s something you always have to ask yourself when writing code (not only when writing models). </p>
<p>@Jelle: To me your scenario sounds like it would make sense to have special methods like saveAsDraft(), saveAsSent(), etc. But it could also make sense to create models for your states, it depends on your requirements.</p>
<p>@Abba: Hm, I wouldn&#8217;t create the Profile in the afterSave() callback function.  I would rather create it at the place where the User is saved, so that you see those two &#8220;actions&#8221; are connected.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fran Iglesias</title>
		<link>http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/comment-page-1/#comment-59498</link>
		<dc:creator>Fran Iglesias</dc:creator>
		<pubDate>Thu, 24 Jan 2008 08:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/01/19/fat-models-and-how-they-change-how-you-use-the-model-class/#comment-59498</guid>
		<description>Thanks Anonymous, I see our point and it clarifies me a bit.

My quest is to find a way to separate &quot;pagination logic&quot; (an put it in the controller) from &quot;bussines logic&quot; (an put it in the model), and pass necesary data to limit the model results.

In my current project model&#039;s find methos have to deal with complex conditions based on user profile, object status, dates... So model encapsulation makes sense.</description>
		<content:encoded><![CDATA[<p>Thanks Anonymous, I see our point and it clarifies me a bit.</p>
<p>My quest is to find a way to separate &#8220;pagination logic&#8221; (an put it in the controller) from &#8220;bussines logic&#8221; (an put it in the model), and pass necesary data to limit the model results.</p>
<p>In my current project model&#8217;s find methos have to deal with complex conditions based on user profile, object status, dates&#8230; So model encapsulation makes sense.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
