Question

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.

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

ServicesGroup service

to simply

Long service

it works.

What's going on here?

Was it helpful?

Solution

Try it that way:

Step.findByService(ServicesGroup.get(3))

OTHER TIPS

Try

grails clean
grails run-app

Then try again.

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.

On the other hand, the abstraction breaks down a bit when you do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top