GORM dynamic methods with inList and OrderBy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

GORM dynamic methods with inList and OrderBy

Paul C
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: GORM dynamic methods with inList and OrderBy

Justin Miranda
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 <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CADxhddTLoahkf3UU1WQrA9fLYxDaJR3_jMdQsj0ZuGfSvdjz3g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: GORM dynamic methods with inList and OrderBy

Paul C
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
<a href="http://docs.grails.org/latest/ref/Domain%20Classes/findAllBy.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdocs.grails.org%2Flatest%2Fref%2FDomain%2520Classes%2FfindAllBy.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHKzbsEfTur-eJKWUTBKnGFjD8BLQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fdocs.grails.org%2Flatest%2Fref%2FDomain%2520Classes%2FfindAllBy.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHKzbsEfTur-eJKWUTBKnGFjD8BLQ&#39;;return true;">http://docs.grails.org/latest/ref/Domain%20Classes/findAllBy.html
def allLocations = Location.findAllByIdInList(locationArray, [sort: "name", order: "asc"])

On Mon, Sep 25, 2017 at 12:53 PM, Paul C <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4LTElgBCBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">pkc...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="4LTElgBCBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">grails-dev-discuss+unsubscribe@....
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="4LTElgBCBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">grails-de...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/grails-dev-discuss/5bb0c49b-087a-471d-9c9a-f47e94eeb926%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/grails-dev-discuss/5bb0c49b-087a-471d-9c9a-f47e94eeb926%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/grails-dev-discuss/5bb0c49b-087a-471d-9c9a-f47e94eeb926%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/grails-dev-discuss/5bb0c49b-087a-471d-9c9a-f47e94eeb926%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/e7447fd6-8fd3-490f-a471-9f1da9177a9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.