我们有一个User类左连接的Grails标准
class User {
...
}
和其他类:
class Licence {
User user
Event event
}
我们想要做的是左连接(因为不是每一个用户,我们有一个条目许可证类)。
我们天真地这样做:
def a = User.withCriteria {
createAlias("Licence", "l", CriteriaSpecification.LEFT_JOIN)
eq("id", "l.user.id")
if (something == true)
isNull("l.id")
else
isNotNull("l.id")
}
但查询失败:
could not resolve property Licence of User
有人可以帮如何做到这一点的查询?
'User'和'Licence'之间的连接性质是什么?它是OneToMany还是OneToOne?在我看来,你需要在用户 – lvojnovic
中使用'static hasOne = [license:License]'或'static hasMany = [licenses:License]',实际上它是一对一的用户。但我还没有宣布hasOne关系,因为我一直有一个hasOne的问题,当hasOne方可以为空... – Bernhard