我正在尝试让所有用户都处于特定年龄段。
我有一个User
表和每个Profile
的User
表。
最小User
域类:
class User {
static hasOne = [profile: Profile]
}
最小
Profile
域类:class Profile {
static belongsTo = [user: User]
Integer age
static constraints = {
age(range: 18 .. 150)
}
}
最小
UserService
域类:class UserService {
def list() {
def users = User.findAll{
gender in whichGenderList
profile.age in 18 .. 150 /* Problem */
}
}
在
Problem
的行上,我在浏览器中遇到以下异常:URI /foo/browse
Class org.hibernate.QueryException
Message could not resolve property: profile_alias0 of: foo.Profile
问题:
在
UserService
中,如何从每个User
的Profile
表中选择其年龄?我正在使用:
谢谢!
最佳答案
使用这样的条件查询:
def users = User.createCriteria().list(){
inList('gender', whichGenderList)
profile{
inList('age', 18 .. 150)
}
}
关于grails - Grails GORM:通过关联查找所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29154097/