开发者

How do I create association by joining non primary key column

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜