使用 Grails/Gorm,我可以通过执行以下操作来定义索引:
class Person {
String firstName
static mapping = {
table 'people'
id column: 'person_id'
firstName column: 'First_Name', index: 'Name_Idx'
}
}
但是,如果我使用连接表,如下所示:
class Employee {
static hasMany = [projects: Project]
static mapping = {
projects joinTable: [name: 'EMP_PROJ',
column: 'PROJECT_ID',
key: 'EMPLOYEE_ID']
}
}
如何配置它以便对连接表中的列建立索引?
谢谢
最佳答案
如果您使用 database migration plugin您可以使用 createIndex更改集以创建索引:
changeSet(author: "..", id: "..") {
createIndex(indexName: "indexname", tableName: "yourtable", unique: "true") {
column(name: "country_code")
}
}
关于hibernate - 在 Grails/Gorm 中索引外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21234536/