1
這些都是我的域對象Grails的標準 - 列表內容
User{
hasMany = {roles: UserRole}
}
UserRole{
User user
Role role
}
Role{
String authority
}
我需要找到基於用戶的角色。對於我嘗試使用下列標準:
def role_admin = Role.findByAuthority('ROLE_ADMIN')
def criteria = new DetachedCriteria(User).build {
roles{
role{
idEq(role_admin.id)
}
}
}
result.users = criteria.list(params)
result.total = criteria.count()
上面總是會返回一個結果,儘管我已經通過在數據庫中查找直接,應該有更多的實驗驗證。傳遞給列表的params
是正確的,但我試圖刪除它們只是爲了確保。我看不出上面有什麼問題,有什麼建議嗎?
我也試過這個
roles{
role{
eq("authority","ROLE_ADMIN")
}
}
但它引發異常:
未知列 'role_alias2_.authority' 在 'where子句'
我在調試中刪除的條件中有更多項目,這就是爲什麼我去標準 – Giannis
我編輯了我的答案,現在我已經使用了標準。 – PhilMr
對,這確實有用。任何線索爲什麼嘗試查詢'權限'字段時失敗? – Giannis