1

私はそのようなドメインクラスを持っています:

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'
    }
}

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'
    }
}

関係は次のとおりです。1 つの ServicesGroup エントリに複数の Step インスタンスを含めることができます。

ただし、コントローラーでしようとすると

Step.findByService(3)

私は得る:

"org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Step.findByService() is applicable for argument types: (java.lang.Integer) values: {3}"

ただし、 Step ドメインクラスフィールドを変更すると

ServicesGroup service

単純に

Long service

できます。

何が起きてる?

4

3 に答える 3

3

そのようにしてみてください:

Step.findByService(ServicesGroup.get(3))
于 2009-05-22T12:00:31.767 に答える
1

Step.findByService([id:3])のようなものが機能する可能性があります。とにかく、SQL生成の目的でIDのみを考慮します。このような多くの場合、本物ではなく偽のマップをそこに投げ入れて、パフォーマンスをいくらか節約することができます。

一方、これを行うと、抽象化が少し崩れます。

于 2009-05-22T14:01:19.603 に答える
1

試す

grails clean
grails run-app

その後、もう一度やり直してください。

于 2009-05-22T10:22:35.553 に答える