0

这是一个语法问题。我想要 Foo -> Bar 之间的一对多关系(此处简化):

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。希望这是有道理的。

我的问题是我不知道语法应该是什么(或者是否有更好的方法来做到这一点!)从我能找到的情况来看,grails 文档并没有真正的帮助。

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 回答