Probably because he doesn't know about recursion (yet)?
A find('all') command will do exaclty that, find all... So if you do a
find('all') of the posts, itll also get all the commens, tags, users,
whatever the post has relationships with... If in a certain action you
just need the posts, add $this->Product->recursive = 0; before the
call. It'll limit the search to only posts. (recursive is kinda like a
depth-level of search)



On 23 okt, 09:05, AD7six <andydawso...@gmail.com> wrote:
> On 23 oct, 05:32, bonecandy <boneca...@gmail.com> wrote:
>
>
>
> > Hi, this is my first post here - I'm new to CakePHP, but not to
> > programming or PHP.
> > Anyway, to get acquainted with Cake I've been making a blog (I know,
> > crazy, huh?). So, I have my posts table and model, which has a hasMany
> > relationship with comments, and my comments table and model, which has
> > a belongsTo relationship with my post model.
> > This works just fine - I'm using the paginate helper like so:
>
> > $this->set('posts',$this->paginate('Post'));
>
> > And I can access the comments just fine. However, the problem is the
> > query is so inefficient!
> > These are the queries Cake produces that I have issues with:
>
> > SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`,
> > `Post`.`date_created`, `Post`.`date_modified` FROM `posts` AS `Post`
> > WHERE 1 = 1 ORDER BY `Post`.`id` desc LIMIT 20
>
> > SELECT `Comments`.`id`, `Comments`.`user`, `Comments`.`body`,
> > `Comments`.`post_id` FROM `comments` AS `Comments` WHERE
> > `Comments`.`post_id` IN (22, 21, 20, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4,
> > 3, 2, 1)
>
> > The 'IN' MySQL operator is  slow.
>
> How slow. Feel free to propose an alternative that achieves the same
> thing.
>
> > More importantly, that extra query
> > is unnecessary!
>
> So don't ask for it :)
>
> > Is it possible to get CakePHP to combine the two and
> > produce something like this?
>
> > SELECT `Post`.`id`, `Post`.`title`, `Post`.`url_title`, `Post`.`body`,
> > `Post`.`date_created`, `Post`.`date_modified`,`Comments`.* FROM
> > `posts` AS `Post` LEFT JOIN `comments` AS `Comments` ON
> > `Comments`.`post_id` = `Post`.`id` ORDER BY `Post`.`id` desc LIMIT 20
>
> > I've searched this group as well as Google and haven't really found
> > much of anything about this.
>
> Post hasOne Comment would generate that - but good luck paginating it.
> As soon as any post has more than 1 comment your post index is going
> to have duplicates or holes (depending on if/how you try to 'fix'
> that). But why are you requesting comments at all?
>
> AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to