Results 1 to 2 of 2

Thread: Grails domain class

  1. #1
    Join Date
    Dec 2011
    Posts
    1

    Exclamation 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. #2
    Join Date
    Sep 2010
    Posts
    26

    Default

    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 ) )
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •