Given the example from grails doc:
class Airport {
…
static hasMany = [flights: Flight]
static mapping = {
flights sort: 'number', order: 'desc'
}
}
How can one test sorting?
Given the example from grails doc:
class Airport {
…
static hasMany = [flights: Flight]
static mapping = {
flights sort: 'number', order: 'desc'
}
}
How can one test sorting?
For sorting in case of association, simply do the following:
I am using 2.4.4 and it is working perfectly.
As stated in the docs, it does not work like written. You have to add
static belongsTo = [airport:Airport]
to Flight.Without belongsTo you get the following error:
Default sort for associations [Airport->flights] are not supported with unidirectional one to many relationships.
With belongsTo the test could look like this:
But.. it doesn't make much sense to write a test like this because it checks that grails applies the sorting configuration. Why would I want to test grails? Test your code and not the framework.