繁体   English   中英

Grails单向多对一和标准

[英]Grails Unidirectional Many to One and Criteria

有什么办法可以查询(标准)单向多对一关系中一侧受限的多方列表

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应该可以工作,但是除了查询之外,还有其他方法可以使用其他标准。

如果没有查询的地方查询和分离的条件,则一个选项将使用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' ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM