Open chrisbitmead opened 3 years ago
I think that instead of findAll(), you can just use list() Anyway according to the documentation, the following parameter order is supported
Book.findAll()
Book.findAll(String query)
Book.findAll(String query, Collection positionalParams)
Book.findAll(String query, Collection positionalParams, Map queryParams)
Book.findAll(String query, Map namedParams)
Book.findAll(String query, Map namedParams, Map queryParams)
Book.findAll(Book example)
Book.findAll(Closure whereCriteria)
Book.findAll(Map queryParams, Closure whereCriteria)
http://docs.grails.org/latest/ref/Domain%20Classes/findAll.html
So I don't think this is a bug.
Well... if I'm passing a Map as the first parameter, as far this documentation is concerned, surely I'd be calling this one:
Book.findAll(Map queryParams, Closure whereCriteria)
And since queryParams is defined as queryParams - A Map containing parameters 'max', and/or 'offset' and/or 'cache'
aka... this is the thing that usually contains the sort stuff, I don't see why this shouldn't be expected to work.
And does not the documentation have a findAll with sort as the first parameter: (albeit with a closure)
def results = Person.findAll(sort:"firstName") {
lastName == "Simpson"
}
My question is, if Booking.findAll([sort: ['email': 'desc', 'lastUpdated': 'desc']])
doesn't mean what it looks like it means, what does it mean? I mean, there's no runtime error, no compile error, so what does findAll with first argument map mean?
As far as whether list([sort: ['email': 'desc', 'lastUpdated': 'desc']])
would be a solution, as far as I see, calling findAll, calls this:
static List<D> findAll(Map params = Collections.emptyMap()) {
currentGormStaticApi().findAll params
}
which calls this:
List<D> findAll(Map params = Collections.emptyMap()) {
list(params)
}
And you end up calling list. So if findAll doesn't work, list surely can't work.
The other thing is, while obviously findAll isn't a dynamic finder, surely for the sake of consistency it should work like a dynamic finder, since for all intents and purposes, the findAll and findAll...dynamic apis look the same. So if... Booking.findAllByVersion(0, [sort: ['email': 'desc', 'lastUpdated': 'desc']])
works, surely Booking.findAll([sort: ['email': 'desc', 'lastUpdated': 'desc']])
should work the same.
if I'm passing a Map as the first parameter, as far this documentation is concerned, surely I'd be calling this one:
Book.findAll(Map queryParams, Closure whereCriteria)
I don't think that is the method you are invoking when you run Booking.findAll([sort: ['email': 'desc', 'lastUpdated': 'desc']])
.
Book.findAll(Map queryParams, Closure whereCriteria)
would invoke https://github.com/grails/grails-data-mapping/blob/1d5f9fbe7605cb0956276257c5893f4c846cfc32/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntity.groovy#L476-L478.
Since Booking.findAll([sort: ['email': 'desc', 'lastUpdated': 'desc']])
is not providing a Closure
, that should invoke https://github.com/grails/grails-data-mapping/blob/1d5f9fbe7605cb0956276257c5893f4c846cfc32/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormEntity.groovy#L690-L692.
Steps to Reproduce
Using a finder with no criteria, the sort criteria doesn't work. e.g.
Booking.findAll([sort: ['email': 'desc', 'lastUpdated': 'desc']])
the sort criteria here has no effect. By contrast, if I do:
Booking.findAllByVersion(0, [sort: ['email': 'desc', 'lastUpdated': 'desc']])
the sort criteria works as expected
Expected Behaviour
Even with no criteria, findAll should sort properly.
Actual Behaviour
No sorting occurs.
Environment Information