I have such domain classes:
我有这样的域类:
class ServicesGroup {
Long id
String name
String description
String toString(){
return name
}
static mapping = {
version false
table 'root.services_groups'
id column:'group_id'
name column:'group_name'
description column:'group_desc'
}
}
and
class Step {
Long id
ServicesGroup service
String stepType
Integer stepFrom
Integer stepTo
static constraints = {
stepType(inList:['operator', 'client'])
}
static mapping = {
version false
table 'bill.steps'
service column:'service_group_id'
}
}
The relationship is - one ServicesGroup entry can have multiple Step instances.
关系是 - 一个ServicesGroup条目可以有多个Step实例。
However, when in my controller I try to
但是,当我在我的控制器中尝试时
Step.findByService(3)
I get:
"org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Step.findByService() is applicable for argument types: (java.lang.Integer) values: {3}"
However, when I change Step domain class field
但是,当我更改Step域类字段时
ServicesGroup service
to simply
Long service
it works.
What's going on here?
这里发生了什么?
3 个解决方案
#1
Try it that way:
试试这样:
Step.findByService(ServicesGroup.get(3))
#2
Try
grails clean
grails run-app
Then try again.
然后再试一次。
#3
Something like Step.findByService([id: 3]) may work. It only cares about the ID anyway for the purposes of the SQL generation. In a lot of cases like this you can toss a fake map into there rather than the real thing, and save yourself some performance.
像Step.findByService([id:3])之类的东西可能有效。出于SQL生成的目的,它只关心ID。在很多这样的情况下,你可以将假地图扔到那里而不是真实的地方,并为自己节省一些性能。
On the other hand, the abstraction breaks down a bit when you do this.
另一方面,当你这样做时,抽象会有所破坏。
#1
Try it that way:
试试这样:
Step.findByService(ServicesGroup.get(3))
#2
Try
grails clean
grails run-app
Then try again.
然后再试一次。
#3
Something like Step.findByService([id: 3]) may work. It only cares about the ID anyway for the purposes of the SQL generation. In a lot of cases like this you can toss a fake map into there rather than the real thing, and save yourself some performance.
像Step.findByService([id:3])之类的东西可能有效。出于SQL生成的目的,它只关心ID。在很多这样的情况下,你可以将假地图扔到那里而不是真实的地方,并为自己节省一些性能。
On the other hand, the abstraction breaks down a bit when you do this.
另一方面,当你这样做时,抽象会有所破坏。