class Contact {
String name
String number
}
class Message {
String text
String number
Contact contactInfo //If any
}
我需要加入 Message.number = Contact.number。关于在 Grails/GORM 中与非主键列创建关联有什么想法吗?
最佳答案
我很确定这在 GORM 中是不可能的,而且我不知道在常规 Hibernate 中是否可能。但你可以伪造它:
class Message {
String text
String number
static transients = ['contactInfo']
Contact getContactInfo() {
Contact.findByNumber(number)
}
void setContactInfo(Contact contact) {
number = contact.number
}
}
关于grails - 如何通过加入非主键列来创建关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6887862/