Saturday, December 27, 2008

Re: I'm not sure how to write this query...

I would do something like (note that you'll need to modify to fit your
data model and field names):

$posts_w_tags = $this->Post->Tag->find('all',
array(
'conditions' => array(
'(select
count(1) from tags Tag where Tag.post_id = '. $this->Post->id .')> '
=> $count
)
)
);

Which basically adds a count to the WHERE clause that Cake builds.

This is much quicker than fetching all the data and doing the count in
your controller, since the database was built to do this sort of
stuff, and Cake has less data to deal with (less network traffic,
etc).


On Dec 26, 8:51 pm, Kyle Decot <kdec...@gmail.com> wrote:
> I'm trying to write a query that finds how many blog posts have more
> then x number of tags. Could anyone provide me with an example of how
> to do this? I would be most grateful.
>
> Thank you as always.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: