Grails : Select all projects where the current user is a member.


/ Published in: Groovy
Save to your folder(s)

Select all projects where the current user is a member.
A project has a set of members where each member is comprised of user and role.


Copy this code and paste it in your HTML
  1. params.max = Math.min(params.max ? params.int('max') : 20, 100)
  2. if (!params.sort) params.sort = "lastUpdated"
  3. if (!params.order) params.order = "desc"
  4. if (!params.offset) params.offset = 0
  5. def user = session.user
  6. def query= "from Project p where exists ( from Member m where p.id = m.project.id and m.user.login='"+user.login+"') order by p." +params.sort+ " " +params.order+ "";
  7.  
  8. def projectList = Project.findAll(query,[max:params.max?.toInteger(), offset:params.offset?.toInteger()])
  9.  
  10. def projectTotalCount = Project.findAll(query).size()
  11.  
  12. [projectInstanceList: projectList, projectInstanceTotal: projectTotalCount]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.