【发布时间】:2012-11-13 15:26:11
【问题描述】:
您好,我在构建命名查询时似乎碰壁了。
我有以下情况: 一个人有一个可选的地址,一个地址有一个可选的国家。
现在我想过滤一堆字段并返回结果 搜索一些文本。
我尝试了以下部分,但是每当一个人有一个位置和地址并且地址没有国家时,我就没有结果。
filterOnAddress { String loc ->
if(!loc.isEmpty()) {
location {
address {
or {
ilike 'street', "%${loc}%"
ilike 'city', "%${loc}%"
country {
or {
ilike 'titleLocal', "%${loc}%"
ilike 'title', "%${loc}%"
}
}
}
}
}
}
}
}
filterOnAddress { String loc ->
if(!loc.isEmpty()) {
location {
address {
or {
ilike 'street', "%${loc}%"
ilike 'city', "%${loc}%"
and {
isNotNull('country')
country {
or {
ilike 'titleLocal', "%${loc}%"
ilike 'title', "%${loc}%"
}
}
}
}
}
}
}
}
只要 Person 的 Country 为空,查询就不会返回 据我所知,一些标准的预期结果是 遇见了!因此,当一个国家/地区为空时,我会期待一些结果。
当国家/地区为空但其他国家/地区为空时,我需要在查询中包含什么 标准是否成功?
【问题讨论】:
-
你能为那个场景构建一个简单的 SQL 查询吗?也许这是一个很好的起点。
标签: grails grails-orm