Request through multiple domain objects in Grails

I am creating a Recent Activity page to give some background. Basically, this page will consist of several different actions performed by the user. The problem is that this data covers several (3 or so) types of domain objects, all with different fields. All domains are associated with a User object, but the associations are different.

Domains are UserPost, FriendRequest, and UserTask. Is there a way I can query all of these domains, support pagination, and sort by date? Would it be better to change my structure? Any help would be great!

+3
source share
1 answer

-, , Activity, .

class Activity {
  Date dateCreated
  String linkClassName
  Long linkId

  def getLink() { getClass().classLoader.loadClass(linkClassName).get(linkId) }
}

, UserPost, FriendRequest UserTask ( - ), Activity, afterInsert GORM :

def afterInsert = {
  new Activity(linkClassName: this.class.name, linkId: this.id).save()
}

, , :

def activities = Activity.list(max: 5, sort:'dateCreated', order:'desc')
+5

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


All Articles