有什么办法,查询单向多对一关系中一侧有限制的多方的(条件)列表
域
class Batch {
String name
Date date
}
class Record {
String type
Batch batch
}
class RecordDetails {
String xx
Record record
}
无论如何,是否有条件查询所有批处理记录,其中batch.date = xx,并且record.type = yy和recordDetails.xx = zz
HQL 应该可以工作,但是除了查询之外,还有其他方法可以处理条件吗?
对于 Where 查询和分离条件,一个选项是使用如下sqlRestriction
:
Batch.withCriteria {
sqlRestriction """
exists (
select * from record r
join record_details rd on rd.record_id = r.id
where
r.batch_id = {alias}.id and
r.type like ? and
rd.xx like ?
)""", [ 'foo', 'bar' ]
}