开发者

How do I create association by joining non primary key column

开发者 https://www.devze.com 2023-03-24 17:05 出处:网络
class Contact { String name String numbe开发者_运维技巧r } class Message { String text String number
class Contact {
String name
String numbe开发者_运维技巧r
}

class Message {
String text
String number   
Contact contactInfo //If any
}

I need to join on Message.number = Contact.number. Any thoughts on creating association in Grails/GORM with non primary key column?


I'm pretty sure this isn't possible in GORM, and I don't know if it's even possible in regular Hibernate. But you can fake it:

class Message {
   String text
   String number

   static transients = ['contactInfo']

   Contact getContactInfo() {
      Contact.findByNumber(number)
   }
   void setContactInfo(Contact contact) {
      number = contact.number
   }
}


Burt, this is possible with hibernate using the property-ref attribute

0

精彩评论

暂无评论...
验证码 换一张
取 消