我的应用程序中有一个多对多关系,如下所示: class
App {
String type
String name
static hasMany = [users: User]
}
class User {
String email
String regid
static belongsTo = App
static hasMany = [apps:App]
}
现在我想要访问一个应用程序的所有用户,通过它的id。
我正在尝试这样做:
def result = sql.eachRow('SELECT App_Users from App where id in(?)' [id:params.app_checkbox])
但这抛出了异常,因为列App_users不可用。
我试着这样做了4-5个小时,记住我不是一个web开发人员,这已经让我发疯了,所以你们能给我一些建议,如何使用sql访问多对多关系的成员吗?
发布于 2015-05-01 19:36:23
最后,我用简单的标准做到了这一点:
def results = App.createCriteria().list() {
createAlias('users', 'user')
'in'("id", goodIds)
projections {
count('users')
}
}
https://stackoverflow.com/questions/29985768
复制相似问题