我有两个表,其中一个(遗留表:A)有两个字段应该作为复合外键,另一个(新表:B)应该使用复合主键作为each row:A has one row:B关系.如何根据GORM描述这些表格?
到目前为止,我已经能够创建一个反映旧表的域类:A
class A {
...
//composite foreign key to link B class
String className;
String eventName;
B b; //instance of B to be related
static mapping = {
table 'a_table';
id column: 'id';
className column: 'class_name';
eventName column: 'event_name';
//b: ???
}
}
Run Code Online (Sandbox Code Playgroud)
哪个有效,但我无法创造new class:B和关系.
我试图将B声明为:
class B implements Serializable{
static auditable = true;
String name;
String className;
String eventName;
static mapping = {
//supposed to make a composite PK
id composite:[className, eventName]
}
}
Run Code Online (Sandbox Code Playgroud)
但这不会用a编译
ERROR context.GrailsContextLoader - Error executing bootstraps: Error evaluating ORM mappings block for domain [com.package.B]: No such property: eventName for class: org.codehaus.groovy.grails.orm.hibernate.cfg.HibernateMappingBuilder
我想要的是:
static mapping = {
...
b composite: [b.className:className, b.eventName:eventName]
//or whatever is the right way for this to be done.
}
Run Code Online (Sandbox Code Playgroud)
为A类让GORM处理这种关系.
您是否尝试使用属性名称而不是使用属性值?
class B implements Serializable{
String name;
String className;
String eventName;
static mapping = {
//supposed to make a composite PK
id composite:['className', 'eventName']
}
}
Run Code Online (Sandbox Code Playgroud)
并在A中映射:
class A {
static hasMany = [ b : B ]
}
Run Code Online (Sandbox Code Playgroud)
无需拥有className或eventName进入A
| 归档时间: |
|
| 查看次数: |
13797 次 |
| 最近记录: |