Friday, June 22, 2012

Re: $this->loadModel and performance

the code below should work fine more detail:

loadModel is not a bad way of doings things, you just don't need it in this case as your User hasMany Post...

Andras Kende

On Jun 22, 2012, at 12:07 PM, JonStark wrote:

But if I have to d this in a User view, I still need to load, isn't it ? 'Post.created' won't be matched in the UserController right ?

Thing is I display all user's posts on user profiles.

But anyway, is loadModel really a bad way of doing things ? Is it really heavier for the server ?

Le vendredi 22 juin 2012 20:33:45 UTC+2, Andras Kende a écrit :
I think you could do as below, without using loadModel…..

$this->paginate = array(
'conditions' => array(
'Post.user_id' => $userId
),
'order' => array(
'Post.created' => 'ASC'
),
'limit' => 100,
'maxLimit' => 100
);
$posts = $this->paginate($this->User->Post);
$this->set(compact('posts'));

check the sql and print_r($posts) …  make sure to only pull data what you need,  use fields, recursive, contain….

Andras Kende



On Jun 22, 2012, at 6:40 AM, JonStark wrote:

Even when having relationships (hasMany and such) implemented, I feel the need to user $this->loadModel to display related data. Indeed, when a User has 450 posts, there is a need to limit the number of associated data returned. But when I want to paginate all posts for a user profile, I use $this->loadModel .

But my question is : does it have an inpact on general performance ?

Thanks for your answers/ experience.

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php


--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: