Thanks a lot, That saved the day :)
For reference, what worked was this set of parenthesis: '((Modelname.foreign_id>0)) AS result' /Martin On Feb 11, 12:40 pm, grigri <[email protected]> wrote: > I haven't tried this in a while, but I seem to remember adding extra > parentheses helped. > > Try these: > > '(Modelname.foreign_id>0 AS result)' > '(Modelname.foreign_id>0) AS result' > '((Modelname.foreign_id>0) AS result)' > '(((Modelname.foreign_id>0) AS result))' > > One of them _should_ work > > hth > grigri > > On Feb 11, 11:34 am, Martin Westin <[email protected]> wrote: > > > Hi, > > I am trying to order by a calculation (in a pagination) but my > > calculation is being backticked to death. I can't find a way to write > > this so that is works. > > > I have: > > > var $paginate = array( > > 'Modelname' => array( > > 'fields'=>array( > > 'Modelname.id', > > 'Modelname.fieldname', > > 'Modelname.foreign_id', > > 'Modelname.foreign_id>0 AS result' // no matter > > what I put here I > > get an sql syntax error > > ), > > 'limit' => 10, > > 'order' => 'result ASC, Modelname.fieldname ASC' > > ) > > ); > > > This results in: > > SELECT `Modelname`.`id`, `Modelname`.`fieldname`, > > `Modelname`.`foreign_id`, `Modelname`.`foreign_id>0` AS `result` > > FROM... > > > and about 10 other variations I have tried. If I just copy the query > > and remove the badly placed backticks I get a working query. I just > > can't figure out how to "trick" Cake into not messing with the > > calculation. Doing simple SUM(somefield) AS some_sum has never caused > > any problems but I have not been able to find a "function" in MySQL > > that would do a simple "greater than" comparison. > > > thanks in advance > > /Martin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
