Select query using the condition

前端 未结 1 955
情书的邮戳
情书的邮戳 2021-01-29 14:37

I have three tables here.The user is able to apply the training available.when he/she selects the training then it is placed at TRAINUSER table according to his/her userID. I wa

1条回答
  •  被撕碎了的回忆
    2021-01-29 15:25

    Some of this will depend on what your domain classes look like, you could use executeQuery like so:

    Training.executeQuery( "from Training tr where tr.id not in ( select t.id from TrainUser tu join tu.training t join tu.user u where u.username = :uname )", [uname: 'ADMIN'] )
    

    Assuming the following domains, only relevant fields included:

    class User {
        String username
    }
    
    class TrainUser {
        static hasMany = [training: Training, user: User]
    }
    
    class Training {
        String name
    }
    

    0 讨论(0)
提交回复
热议问题