What is the best way to declare sorted association in grails domain classes ?

Posted by fabien7474 on Stack Overflow See other posts from Stack Overflow or by fabien7474
Published on 2010-05-15T13:57:55Z Indexed on 2010/05/15 14:04 UTC
Read the original article Hit count: 263

Filed under:
|
|

It seems that there are two different ways of declaring sorted associations in Grails :

Method 1 (see here) using default sort order

class Book {
  String title 
}
class Author {
  static hasMany = [books : Book]
  static mapping = { books sort: "title"}
}

Method 2 (see here) using SortedSet

class Book implements Comparable {
  String title
  int compareTo(obj) {
    title <=> obj.title
  }
}
class Author {
  SortedSet books
  static hasMany = [books : Book]
}

I am not sure which one to use and what is the difference (if any), pros and cons between using one against the other.

I would appreciate any clarification.

Thank you

© Stack Overflow or respective owner

Related posts about gorm

Related posts about grails