Sort list of links in grails

Let's say I have some simple classes for a twitter-like application:

  • User
  • Message

The user has many messages, and the record belongs to the user.

Now I am trying to get a list of messages for a specific user in date order .

I know that I can get a list of all messages (for all users):

def posts = Post.list([sort: 'dateCreated', order: 'asc', max:10])

But to limit it to my specific user, I need to go to the user I want, and I assume that I need to go from a static call to something like this when I first refer to the user:

def user = User.findByUserId(userId)
def posts = user.posts

, , , , [sort: 'dateCreated', order: 'asc', max: 10] 10 ?

?

+3
2

, :

def user = User.findByUserId('steve')
def posts = Post.findAllByUser(user, [sort: 'dateCreated', order:'asc', max: 10])
+7

, User. - :

static mapping = {
    posts sort:'dateCreated', batchSize:10
}
+4

Source: https://habr.com/ru/post/1715424/


All Articles