我正在尋找一個更簡單的Grails方式(如果存在)以下來實現:的Grails GORM的對象屬性的財產找到
我UserIntegration.groovy域類:
class UserIntegration {
User user
Integration integration
// rest of code
}
我Integration.groovy域:
class Integration {
SomeType type
// rest of code
}
我SomeType.groovy域:
class SomeType {
String name
// rest of code
}
所以基本上我需要的是一種方式,以便我能找到一個UserIntegration
具有Integration
與type.name = "someTypeName"
換句話說,我要尋找UserIntegration.findByIntegrationTypeName("someTypeName");
顯然,這種動態取景器不存在,但有沒有更簡單的更方便的方法來做到這一點?我現在可以找到所有類型爲「someTypeName」的Integration對象,然後在findAllByIntegration
中使用此集成,但是如果存在,則尋找更簡單的解決方案,最好是動態查找器。
是否'UserIntegration.where {integration.type.name == 'someTypeName'}'工作? –
@tim_yates是的,它按預期工作,因爲它實際上是使用標準。任何其他方式來做到這一點? – rahulserver
添加一個[命名查詢](https://grails.github.io/grails-doc/latest/ref/Domain%20Classes/namedQueries.html)? –