Grails

Add default sort and order by property to domain classes

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.3.1
  • Fix Version/s: 1.2-M1
  • Component/s: Persistence
  • Labels:
    None

Description

I would be nice if you could specify a default sort and order for domain classes, like:

class NewsArticle { static defaultSort = 'publishedAt' static defaultOrder = 'desc' String title Date publishedAt .... }

Activity

Hide
Josh Brown added a comment -

I found that this doesn't work when the property is a camelCased word. For example:

<pre>
class Book {
Date dateCreated
}

class Author {
static hasMany = [books:Book]

static mapping = { books sort:'dateCreated' }
}
</pre>

Running the app produces an exception similar to the following:

ERROR util.JDBCExceptionReporter - Column not found: BOOKS0_.DATECREATED in statement ...

The problem is that the database column is date_created, not datecreated. The camelHumps property should be translated in the query to two words separated by an underscore.

Show
Josh Brown added a comment - I found that this doesn't work when the property is a camelCased word. For example: <pre> class Book { Date dateCreated } class Author { static hasMany = [books:Book] static mapping = { books sort:'dateCreated' } } </pre> Running the app produces an exception similar to the following: ERROR util.JDBCExceptionReporter - Column not found: BOOKS0_.DATECREATED in statement ... The problem is that the database column is date_created, not datecreated. The camelHumps property should be translated in the query to two words separated by an underscore.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: