Quantcast

Use where query to sort by multiple fields

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Use where query to sort by multiple fields

Dean Del Ponte-2
Is it possible to use the where query to sort on multiple fields of a domain class?

If so, have any examples?

Thanks!

- Dean Del Ponte
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use where query to sort by multiple fields

Gary Affonso

On Jun 15, 2012, at 6:03 AM, Dean Del Ponte wrote:

> Is it possible to use the where query to sort on multiple fields of a domain class?
>
> If so, have any examples?

Are the docs not working for you?

  http://grails.org/doc/latest/guide/GORM.html#whereQueries

They show a variety of examples of a two-field search (using Groovy concatenation operators between fields).

- Gary
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use where query to sort by multiple fields

longwa
He said "sort", not "search" and the docs don't really show an example of it.

I think you can just call .order() on the DetachedCriteria object:

MyObject.where {
  someAttribute == "FOO"
}.order("somethingFirst").order("somethingElse", "desc").list()

-Aaron

On Fri, Jun 15, 2012 at 12:06 PM, Gary Affonso <[hidden email]> wrote:

On Jun 15, 2012, at 6:03 AM, Dean Del Ponte wrote:

> Is it possible to use the where query to sort on multiple fields of a domain class?
>
> If so, have any examples?

Are the docs not working for you?

 http://grails.org/doc/latest/guide/GORM.html#whereQueries

They show a variety of examples of a two-field search (using Groovy concatenation operators between fields).

- Gary
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use where query to sort by multiple fields

Gary Affonso

On Jun 15, 2012, at 11:22 AM, Aaron Long wrote:

> He said "sort", not "search" and the docs don't really show an example of it.

Doh!  Sorry about that.

- Gary
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Use where query to sort by multiple fields

Dean Del Ponte-2
In reply to this post by longwa
Worked great!  Thanks!

- Dean Del Ponte

On Fri, Jun 15, 2012 at 1:22 PM, Aaron Long <[hidden email]> wrote:
He said "sort", not "search" and the docs don't really show an example of it.

I think you can just call .order() on the DetachedCriteria object:

MyObject.where {
  someAttribute == "FOO"
}.order("somethingFirst").order("somethingElse", "desc").list()

-Aaron

On Fri, Jun 15, 2012 at 12:06 PM, Gary Affonso <[hidden email]> wrote:

On Jun 15, 2012, at 6:03 AM, Dean Del Ponte wrote:

> Is it possible to use the where query to sort on multiple fields of a domain class?
>
> If so, have any examples?

Are the docs not working for you?

 http://grails.org/doc/latest/guide/GORM.html#whereQueries

They show a variety of examples of a two-field search (using Groovy concatenation operators between fields).

- Gary
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




Loading...