我正在使用grails 2.4.2。我需要创建一个基于查询类似关键字的列表。假设这是一个例子>>grails用父类和子域的查询创建一个列表
def results = c.list(max: iDisplayLength, offset: iDisplayStart) {
and {
// eq("activeStatus", ActiveStatus.ACTIVE)
}
if (sSearch) {
or {
ilike('title', sSearch)
ilike('shortDesc', sSearch)
}
}
}
在这里,我可以搜索字段与sSearch参数。但是,假设在这个域中我有一个名为Parent parent的父域实例。现在,如果我也想用sSearch检查parent.typeName的值,那么我应该怎么做。我试过如下>>
or {
ilike('title', sSearch)
ilike('shortDesc', sSearch)
ilike('parent.typeName', sSearch)
}
但它给出了错误。其实我想为数据表做这个。在搜索选项下保留父类字段。有什么办法与父类对象做到这一点?你们能帮忙吗?
我的域名 音频领域>>
package streaming
class Audio {
static mapping = {
table('audio')
version(false)
}
String title
// StreamType streamType
String shortDesc
String filePath
String imagePath
String imageName
int downloadCount
boolean isActive
static belongsTo = [streamType: StreamType]
static constraints = {
title(nullable: false, blank: false,unique: true)
shortDesc(nullable: false, blank: false)
filePath(nullable: false, maxSize: 2000)
imagePath(nullable: false, maxSize: 2000)
imageName(nullable: false)
downloadCount(nullable: true)
}
String toString(){
return title
}
}
流类型域>>
package streaming
class StreamType {
static mapping = {
table('stream_type')
version(false)
}
String typeName
static hasMany = [audio: Audio, video: Video]
static constraints = {
typeName(nullable: false, blank: false)
}
String toString(){
return typeName
}
}
您可以直接访问父属性,没有必要提及父母。尝试'ilike('typeName',sSearch)' – user1690588
@ user1690588我试过你的方式,但它显示以下错误>>'消息:无法解析属性:typeName:streaming.Audio' –
你能发布你的域名吗? – user1690588