On Apr 12, 11:23 am, Alterego <[email protected]> wrote:
> Hi there,
>
> I have a small issue that kept me busy for a whole day now.
>
> I want to sort on a psuedofield, so I use this code in the controller:
>
> function index() {
>                 $this->Contract->recursive = 0;
>
>                 $this->paginate = array(
>                   'fields' => array('*', 'COALESCE(price_month_action,
> price_month_regular) AS price_month_least'),
>                         'limit' => 500,
>                         'order' => array('price_month_least' => 'asc'));
>
>                 $this->set('contracts', $this->paginate());
>         }
>
> This works, but the 'price_month_least' value is outside of the
> Contract array + sorting doesn't work when I pass the sorting
> arguments in the URL like so: /contracts/index/sort:price_month_least/

I can't remember offhand if it's possible, but have you tried adding:

'sort' => 'price_month_least'

... to your paginate array? I mean, just temporarily, to see if Cake
will allow it.


> I tried to add the pseudofield in the beforeFind in the Model, but
> that didn't solve the problem. Could anybody help me out?

This post has a good solution for dealing with calculated fields in
afterFind()

http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to