Grails GORM按对象属性的属性查找
我正在寻找一种更简单的grails方法,如果可以实现以下目标: My UserIntegration.groovy域类:Grails GORM按对象属性的属性查找,grails,groovy,gorm,Grails,Groovy,Gorm,我正在寻找一种更简单的grails方法,如果可以实现以下目标: My UserIntegration.groovy域类: class UserIntegration { User user Integration integration // rest of code } My Integration.groovy域: class Integration { SomeType type // rest of code } class SomeType { String name
class UserIntegration {
User user
Integration integration
// rest of code
}
My Integration.groovy域:
class Integration {
SomeType type
// rest of code
}
class SomeType {
String name
// rest of code
}
My SomeType.groovy域:
class Integration {
SomeType type
// rest of code
}
class SomeType {
String name
// rest of code
}
所以基本上我需要的是一种方法,这样我可以找到一个与type.name=someTypeName集成的UserIntegration
换句话说,我正在寻找UserIntegration.findByIntegrationTypeNamesomeTypeName
显然,这样的动态查找器并不存在,但是有没有更简单的groovier方法呢?我目前可以找到type=someTypeName的所有集成对象,然后在findAllByIntegration中使用此集成,但如果存在,我会寻找一个更简单的解决方案,最好是动态查找器 您也可以使用HQL执行相同的操作
def list = UserIntegration.executeQuery(from UserIntegration userInt
inner join fetch userint.integration integration
inner join fetch integration.type sometype
where sometype.name =:name,[name:'someTypeName'] )
希望它能工作UserIntegration.where{integration.type.name=='someTypeName'}能工作吗?@tim_-yates是的,它能像预期的那样工作,因为它使用了criterias。还有其他方法吗?添加?@tim_yates我正在寻找更多的方法将我自己的动态findByIntegrationTypeName添加到UserIntegration类中。也许可以编写一个插件,将此工作推广到任何域类?这不是命名查询所提供的吗?