how to made one-to-one bidirectional relationships in grails?
Posted
by
user369759
on Stack Overflow
See other posts from Stack Overflow
or by user369759
Published on 2010-12-25T09:37:00Z
Indexed on
2010/12/27
4:54 UTC
Read the original article
Hit count: 216
I have two domain classes and want to have one-to-one BIDIRECTIONAL relation between them. I write:
class Person {
Book book;
String name
Integer age
Date lastVisit
static constraints = {
book unique: true // "one-to-one". Without that = "Many-to-one".
}
}
class Book {
String title
Date releaseDate
String ISBN
static belongsTo = [person:Person] // it makes relationship bi-directional regarding the grails-docs
}
So, i want to have bi-directional, i could NOT find link from Book to Person in generated SQL:
CREATE TABLE `book` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`version` bigint(20) NOT NULL,
`isbn` varchar(255) NOT NULL,
`release_date` datetime NOT NULL,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
So then it means it is not bidirectional then? How to make bidirectional?
© Stack Overflow or respective owner