Re: GORM dynamic methods with inList and OrderBy

7 views
Skip to first unread message

Justin Miranda

unread,
Sep 25, 2017, 2:17:02 PM9/25/17
to grails-de...@googlegroups.com
I believe you need to pass the sort field and order as parameters like the first example in the following docs
def allLocations = Location.findAllByIdInList(locationArray, [sort: "name", order: "asc"])

On Mon, Sep 25, 2017 at 12:53 PM, Paul C <pkc...@gmail.com> wrote:
Need help understanding why this does not work (using recent postgres):

Here is a query  where I thought the OrderBy suffix would work but the generated SQL does not have an order by.  Any insight on what happened here is greatly appreciated.


def allLocations = Location.findAllByIdInListOrderBy(locationArray)

Hibernate:
    /* criteria query */ select
        this_.id as id1_20_0_,
        ...
        this_.path as path8_20_0_,
        ...
    from
        location this_
    where
        this_.id in (
            ?, ?, ?, ?, ?, ?
        )


--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.
To post to this group, send email to grails-dev-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/5bb0c49b-087a-471d-9c9a-f47e94eeb926%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul C

unread,
Sep 25, 2017, 3:30:29 PM9/25/17
to Grails Dev Discuss
Thanks.  I tried to delete this post because of a typo...  it should have been findAllByIdInListOrderByPath .  Anyway shouldn't there be an exception if the OrderByPath does not work?  Please reply using the other posting titled: 

"Dynamic finders with InList and OrderBy issue"

I'm wondering if I should submit a bug.  It should either work or throw an exception right?  BTW we did end up going with your suggestion.


On Monday, September 25, 2017 at 2:17:02 PM UTC-4, Justin Miranda wrote:
I believe you need to pass the sort field and order as parameters like the first example in the following docs
def allLocations = Location.findAllByIdInList(locationArray, [sort: "name", order: "asc"])
On Mon, Sep 25, 2017 at 12:53 PM, Paul C <pkc...@gmail.com> wrote:
Need help understanding why this does not work (using recent postgres):

Here is a query  where I thought the OrderBy suffix would work but the generated SQL does not have an order by.  Any insight on what happened here is greatly appreciated.


def allLocations = Location.findAllByIdInListOrderBy(locationArray)

Hibernate:
    /* criteria query */ select
        this_.id as id1_20_0_,
        ...
        this_.path as path8_20_0_,
        ...
    from
        location this_
    where
        this_.id in (
            ?, ?, ?, ?, ?, ?
        )


--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages