I consider Cake's model the only drawback of Cake in my daily work.
Since I usually operate with large amounts of complex associations in my
models, I have developed three relatively painful work patterns:
1. I use Containable behavior on almost ALL my models (and use it in
nearly every query I write)
2. I bind associations on-the-fly
3. I write my-own-damn-SQL-join-query myself
This takes up quite a lot of my time to optimize my model queries. 87% of
the time, I do not want *all *the related data and I consider it redundant.
Maybe I'm just a lousy programmer, but I find a big need to treat data as
objects, not just to have them deliver me arrays to cumbersomely fiddle
with. Not to mention the mental overload of planning to save related data...
This would be a dream:
$article = $this->Article->findBySlug($slug);
$user = $this->Auth->user('id');
if ($user->myOwnCustomAuthMethod('view', $article));
foreach($article->comments as $comment) //comments are not loaded until
property is requested
{
if ($comment->author->id == $article->id){
// $comment->author is also an overloaded property, returns Author instance
$authorsComments[] = $comment;
}
}
$article->view_count++;
$article->last_viewed = time();
$article->save();
I think Cake Model has some really strong points that should be kept, like
relation definitions, validation (it's maybe a lot of arrays, but it's
useful) and error handling. But I just prefer data objects over arrays and
I think it would sit perfectly into CakePHP. I feel it would offer a simple
way of adding DRY data logic.
So I say HOORAY for any objectification, even if my example is totally
off-road.
OR at least having the option to easily choose a database layer similar to
Doctrine/Propel, if I wanted. Would be very nice.
--
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.