Announcement Announcement Module
Collapse
No announcement yet.
Grails domain class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grails domain class

    Hello
    I have three domain Classes
    Users, Users-Roles (ID user->IdRole), RolesPrev(IdRole->RoleDescription)
    How can I select all users from Users who has not role with description(3d table) Admin
    How can join three tables in one queri/select/using domain class?
    Is it possible?

  • #2
    Hi,

    Since you didn't post the domain object code, I'm assuming that 'ID user->IdRole' are the columns in the Users-Roles table and not the relationship between the Users and Users-Roles table.

    I had to do something similar in one of my projects. I'm sure there are more elegant ways to accomplish this, but this worked for me.

    Set users = []

    //Get the user ids out of the Users-Roles table
    def userIds = UsersRoles.findAllByIdRole( RolesPrev.findByRoleDescription( "Admin" )?.idRole )

    //Now get the users
    userIds.each() {
    users.add( Users.get( it.IdUser ) )
    }

    Comment

    Working...
    X