#5123: Incorrect find('count') results when using "GROUP BY" and
Controller::paginate()
------------------------------------------+---------------------------------
    Reporter:  bunyan                     |         Owner:          
        Type:  Enhancement                |        Status:  reopened
    Priority:  Low                        |     Milestone:  2.0.0.x 
   Component:  MySQL                      |       Version:  Alpha   
    Severity:  Normal                     |    Resolution:          
    Keywords:  paginate, count, group by  |   Php_version:  PHP 5   
Cake_version:  1.2.0.7296 RC2             |  
------------------------------------------+---------------------------------
Comment (by motin):

 Thanks for your suggestions for a workaround, but none of those works when
 using Translate behavior. [[BR]]

 However, Translate-behavior has partially code ready for this. They have
 special handling for the count code, which builds on using COUNT(DISTINCT
 primarykey)). [[BR]]

 To make it work when group is set, under
 {{{
                 if (is_string($query['fields']) && 'COUNT(*) AS
 '.$db->name('count') == $query['fields']) {
                         $query['fields'] =
 'COUNT(DISTINCT('.$db->name($model->alias . '.' . $model->primaryKey) .
 ')) ' . $db->alias . 'count';
 }}}

 add:
 {{{
                         // Supporting GROUP BY count at least for models
 using Translate, when group is set as a string
                         if (isset($query['group']) &&
 is_string($query['group'])) {
                                 $query['fields'] = 'COUNT(DISTINCT(' .
 $query['group'] . ')) ' . $db->alias . 'count';
                                 unset($query['group']);
                         }
 }}}

 In translate.php

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5123#comment:11>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" group.
To post to this group, send email to tickets-cakephp@googlegroups.com
To unsubscribe from this group, send email to 
tickets-cakephp+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to