Monday, February 9, 2009

GORM 1 to 0..1 relationship issue

Recently I wanted to create one-to-one relationship (1 to 0..1) not pure 1 to 1. But unfortunately faced with the problem. Let's review it in details (entity A can have association with zero or only one entity B):
class A {
B b

static constraints = {
b(nullable: true)
}

}

class B {
A a

static belongsTo = [A]
}

Grails generated the database schema in such way: table A has column b_id (as it has to be), but it cannot be nullable. As You can see for 1 to 0..1 relationship this is a wrong behavior. I posted question on Nabble forums (as I recommended to everyone:) ) and received answer that mentioned problem will be fixed in Grails 1.1. For more details visit appropriate forum post.

No comments:

Post a Comment