its the multiple ordering of a single field. this is what cake1.2
lacks i guess.
when cake generates the SQL code for getting the model's data, there
is an error in the code.

this is what it generates currently (with an error):
...... ORDER BY User`.`id` >= 2 DESC, `User`.`id` ASC
note that, there is a ` missing before User (right after ORDER BY)

it should be like this (correct one):
...... ORDER BY `User`.`id` >= 2 DESC, `User`.`id` ASC

how do i overcome this problem?


On Jun 30, 3:20 am, Fahad <[EMAIL PROTECTED]> wrote:
> your SQL idea is absolutely correct grigri. but whenever i apply it on
> cakephp1.2RC1, i get SQL errors.
> i have tried everything, but still cake will just not allow me to
> execute that ordering command.
>
> this is the code that i used on phpMyAdmin to get my desired output:
> =============
>  SELECT *
> FROM `users`
> ORDER BY id >=2 DESC , id ASC
> LIMIT 0 , 30
>
> works fine on phpMyAdmin
> =============
>
> i have tried it on cake:
> =======================
> $users_list = $this->User->find('all', array('order' =>"(User.id>=2)
> DESC, User.id ASC"));
>
> and i get this error:
> SQL Error: 1064: You have an error in your SQL syntax; check the
> manual that corresponds to your MySQL server version for the right
> syntax to use near 'User`.`id`>=2)` DESC,  `User`.`id` ASC' at line 1
> [CORE\cake\libs\model\datasources\dbo_source.php, line 501]
> =======================
>
> On Jun 20, 9:49 pm, grigri <[EMAIL PROTECTED]> wrote:
>
> > > Please don't do that directly. SQL (even in a limited form) sprinkled
> > > throughout the app is never good.
>
> > > I do think that is a neat solution. However, the right way to implement
> > > it would be to define a custom model method called 'findAllSliced()' or
> > > something similar, so you can change the behavior in the future without
> > > grepping and replacing sprinkles of code all over.
>
> > Good point. If this is to be used in a lot of places, then yes, it
> > should be generalized (in some way).
>
> > If it's only used once, it's not worth it from any point of view.
>
> > I always apply the 3rd strike rule to messy hacks / exceptions, and so
> > far it's never let me down.
--~--~---------~--~----~------------~-------~--~----~
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