#5666: Pagination - unable to sort by custom aliased fields
---------------------------+------------------------------------------------
    Reporter:  morris082   |          Type:  Enhancement
      Status:  new         |      Priority:  Medium     
   Milestone:  1.2.x.x     |     Component:  Helpers    
     Version:  RC3         |      Severity:  Normal     
    Keywords:  pagination  |   Php_version:  PHP 5      
Cake_version:              |  
---------------------------+------------------------------------------------
 When using pagination I can't sort by custom aliased fields from my query.
 [[BR]][[BR]]


 For example if I include an extra field, such as "COUNT(some_other_field)
 AS numStuff" I cannot sort by 'numStuff'.
 [[BR]][[BR]]


 I poked around the options but found nothing. I tried to extend/customize
 the pagination query for my model, but the 'order' field was not being
 passed in.
 [[BR]][[BR]]


 There is a simple solution here, though it does open up possiblity of non-
 existent field sorting, but I don't think that is a big risk.
 [[BR]][[BR]]


 In controller.php, line 948, in function paginate, add one more else
 statement so it becomes:

 {{{
 if (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
         $options['order'][$alias . '.' . $field] = $value;
 } elseif ($object->hasField($field)) {
         $options['order'][$alias . '.' . $field] = $value;
 }else{
         $options['order'][$field] = $value;
 }
 }}}

 This way if I attempt to sort by 'numStuff', and it doesn't exist as a
 field of the model, it will still be used in query for the order.

-- 
Ticket URL: <https://trac.cakephp.org/ticket/5666>
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to