grigri
thanks much for this.. It works however there are a few artifacts that I am
seeing, not sure if this is expected or if i should
fish elsewhere (I have included my code below, top level is Event, Child is
Cluster. Here are the things I noticed:

1) When it does the query it does a ton of single selects: e.g.

SELECT `Event`.`id`, `Event`.`description`, `Event`.`created`,
`Event`.`modified`, COUNT(`ClusterCount`.`id`) AS cluster_count FROM
`events` AS `Event` LEFT JOIN `clusters` AS `ClusterCount` ON
(`ClusterCount`.`event_id` = `Event`.`id`) WHERE 1 = 1 GROUP BY `Event`.`id`
ORDER BY `cluster_count` DESC424218SELECT COUNT(`ClusterCount`.`id`) AS
cluster_count FROM `clusters` AS `ClusterCount` WHERE
`ClusterCount`.`event_id` = 331109SELECT COUNT(`ClusterCount`.`id`) AS
cluster_count FROM `clusters` AS `ClusterCount` WHERE
`ClusterCount`.`event_id` = 13
Not sure if this is normal and why this was happening?!?!

2) I also noticed the following notice in debug mode...

*Notice* (8) <javascript:void(0);>: Undefined index:  ClusterCounts
[*CORE/cake/libs/model/datasources/dbo_source.php*, line *926*]

Code <javascript:void(0);> | Context <javascript:void(0);>

                $data[$association] = $merge[$association][0];
   } else {                if (count($merge[0][$association]) > 1) {


Which is odd because the query looks fine and i get the correct
results. Once again not sure if i am introducing any artifacts.


Thanks in advance. Your response saved me so much time thus far!!!!

matt


// My code

$this->Event->bindModel(array(

  'hasOne' => array(

   'ClusterCount' => array(

     'className' => 'Cluster',

     'fields' => 'COUNT(ClusterCount.id) AS cluster_count'))));

     $events = $this->Event->find('all',

     array('recursive' => 2,'group' => 'Event.id','order' => 'cluster_count
DESC'));

On Mon, Oct 6, 2008 at 7:23 AM, grigri <[EMAIL PROTECTED]> wrote:

>
> $this->Article->bindModel(array(
>  'hasOne' => array(
>    'ReviewCount' => array(
>      'className' => 'Review',
>      'fields' => 'COUNT(ReviewCount.id) AS review_count'
>    )
>  )
> ));
> $articles = $this->Article->find('all', array(
>  'group' => 'Article.id',
>  'order' => 'review_count DESC'
> ));
>
> hth
> grigri
>
> On Oct 4, 1:50 am, "Matthew Camuto" <[EMAIL PROTECTED]> wrote:
> >  Apologies in advance. GMAIL auto-sent my last emal before finishing!!!!!
> >
> > hi there
> >
> > thsi group is great firstly and i have been doing pretty well with cake.
> > however i was trying something that is either
> >
> > absurdly simple or not possible. i want to get my model out (via db) but
> i
> > want to sort it based on the count of a set
> >
> > of children (has many). The simplist example is
> >
> > Article
> >
> > has many Reviews
> >
> > And I want to retrieve all the articles orderd solely on Review count. I
> was
> > not sure if I could do this strictly through
> >
> > query or in a combo of a query along with the 'Set' helper class or if I
> > would have to write my complete own sorting function..
> >
> > Thanks in advance
> >
> > matt
> >
>

--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to