Grails 搜索并获取包含具有值的子级的所有父级
我有这个,我想让所有的客户参加课程,课程名为blabla“Grails 搜索并获取包含具有值的子级的所有父级,grails,groovy,Grails,Groovy,我有这个,我想让所有的客户参加课程,课程名为blabla“ 我试着做:Clients.findWhere(Course.any{Course->Course.name=“math”})你可以通过以下条件来做: class Client { String name static hasMany = [courses:Course] } class Course { String name static belongsTo = [client:Client] }
我试着做:Clients.findWhere(Course.any{Course->Course.name=“math”})你可以通过以下条件来做:
class Client {
String name
static hasMany = [courses:Course]
}
class Course {
String name
static belongsTo = [client:Client]
}
Client.withCriteria {
courses {
eq('name', 'math')
}
}
我认为以下条件与上述条件相当:
class Client {
String name
static hasMany = [courses:Course]
}
class Course {
String name
static belongsTo = [client:Client]
}
Client.withCriteria {
courses {
eq('name', 'math')
}
}
或者,您可能会发现您需要另一次关闭:
Client.where { courses.name == 'math' }
但是我自己很少使用where查询,所以我不是100%确定。可能有很多不同的语法表达式来实现相同的功能。我可以肯定地说,这在我的项目中是可行的
Client.where {
courses {
name == 'math'
}
}
它返回一个错误“没有方法的签名:Test.Client.list()适用于参数”。。而不是列表对我来说很好,我使用的是Grails2.1.0