0

これは構文の問題です。Foo -> Bar 間の 1 対多の関係が必要です (ここでは簡略化):

class Foo {
    String fooPK1, fooPK2

    static mapping = {
        id composite: ["fooPK1", "fooPK2"]
    }

    static hasMany = [bars: Bar]
}

class Bar {
    String fooPK1, dumbNameForFooPK2, barPK1, barPK2
    Foo myFoo

    static mapping = {
        id composite: ["barPK1", "barPK2"]
        columns {
            myFoo[:] {
                column name: "FOO_PK_1"
                column name: "?????????????"
            }
        }
    }
}

この場合、明らかに Foo.fooPK1 は Bar.fooPK1 にマップされますが、Foo.fooPK2 を Bar.dumbNameForFooPK2 にマップする必要があります。うまくいけば、これは理にかなっています。

私の問題は、構文がどうあるべきか (または、これを行うためのより良い方法があるかどうか!) がわからないことです。

4

1 に答える 1

1

Bar 内の外部キー列宣言の名前を変更する必要があります。

class Bar {
  Foo myFoo

  static mapping = {
    columns {
      myFoo {
        //declare them in the order of your id composite.
        column name: "foo_pk_1"
        column name: "dumb_name_for_foo_pk_2"
      }
    }
  }

}
于 2013-05-10T17:03:36.293 に答える