【发布时间】:2011-07-23 07:24:43
【问题描述】:
我有一个要使用 grails 进行的一对多表映射。我有一个无法更改表结构的旧数据库。我已经设置好了所有东西,但我唯一不知道的是如何让 grails 注意到现有的外键而不是创建它自己的列。我有这样的东西(简化):
class Customer {
String listID
String name
String address
// more fields etc.
static hasMany [notes : Note]
static mapping = {
table name:"customers"
id name:"listID",generator:"assigned"
// doesn't work, creates a foreign key column in customer_notes table
// with key: customer_id. I want it to just use the existing column
// CustomerListID, which has the correct foreign key
notes joinTable:[name:"customer_notes",key:"CustomerListID"]
}
}
class Note {
String noteID
String customerListID
static mapping = {
table name:"customer_notes"
id name:"NoteID",generator:"assigned"
}
}
作为旁注,我看到 grails 文档中的 joinTable 说“column”是反列,“key”是外键。文档中的示例没有帮助。我有“Grails in Action”,它说它将提供一个一对多的例子,然后显示一个多对多的例子,无论哪种方式,它似乎都不是一个完整的例子(模型的一半缺失) !
有什么想法吗?我有这个遗留数据库,我打算以只读方式使用它。我只是希望 O/R 映射器能够很好地将事物连接在一起。
【问题讨论】:
标签: hibernate grails grails-orm