我有Parent
两个类,Child1
并Child2
从中继承:
class Parent { }
class Child1 extends Parent {
String prop1
}
class Child2 extends Parent {
String prop2
}
现在,我需要写出选择所有上级父类的内容,但条件是prop1
和prop2
,例如:
DetachedCriteria crit = Parent.where {
(prop1 == 'Some value') || (prop2 == 'Some value')
}
crit.list()
我怎样才能做到这一点?
简短的答案是,您不能基于子类的属性来查询类,除非它们是继承的。父级在您的示例中没有子类的属性的概念,因为它们不是继承的,因此无法进行查询。最好的解决方案是分别查询每个子类,然后合并结果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句