Message from discussion
Custom orderBy with FIELD
MIME-Version: 1.0
Received: by 10.100.132.4 with SMTP id f4mr47106and.13.1247102644039; Wed, 08
Jul 2009 18:24:04 -0700 (PDT)
Date: Wed, 8 Jul 2009 18:24:03 -0700 (PDT)
In-Reply-To: <00fb01ca002f$a9d40db0$fd7c2910$@com>
X-IP: 123.243.104.134
References: <40275916-834d-4b64-af19-1589226faf6a@t11g2000prh.googlegroups.com>
<00fb01ca002f$a9d40db0$fd7c2910$@com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1)
Gecko/20090624 Firefox/3.5 FirePHP/0.3 AutoPager/0.5.2.2 (http://www.teesoft.info/),gzip(gfe),gzip(gfe)
Message-ID: <73c0df4d-8fcb-43ba-977a-8932b5ba36c3@d9g2000prh.googlegroups.com>
Subject: Re: Custom orderBy with FIELD
From: conankun <hendrachrist...@gmail.com>
To: doctrine-user <doctrine-user@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hey Phillip,
Ignore my earlier reply, I got it to work with Doctrine_RawSql,
thanks. Here's what I did (for those who face the same thing).
$q =3D new Doctrine_RawSql();
$q->select('{t.*}')
->from('table_name_in_db t')
->addComponent('t', 'Table')
->where('foreign_key_id =3D ?', $foreign)
->orderBy('FIELD(id,2,5,3,6,4,1)');
$result =3D $q->execute()->toArray();
Cheers,
HC
On Jul 9, 10:53=A0am, "J.Philip" <jphi...@noatak.com> wrote:
> You can do this in Doctrine with a RawSql query.
>
> -----Original Message-----
> From: doctrine-user@googlegroups.com [mailto:doctrine-u...@googlegroups.c=
om]
>
> On Behalf Of conankun
> Sent: Wednesday, July 08, 2009 4:48 PM
> To: doctrine-user
> Subject: [doctrine-user] Custom orderBy with FIELD
>
> Hi,
>
> I would like to know if it's possible to do a custom orderBy with
> Doctrine? In other words, is there any Doctrine equivalent to this
> SQL:
>
> SELECT * FROM `table` ORDER BY FIELD(id,2,5,3,6,4,1);
>
> I know I can do a normal Doctrine_Query and traverse the results array
> and do manual sorting (which is my current alternative), however it
> would be good if I can just grab the custom sorted data straight from
> the SQL (since MySQL also supports this).
>
> If it's currently not possible, I hope it will be added in the future,
> thx.
>
> PS: Let me know if this suppose to be a support ticket or something.
>
> Cheers,
> HC
>