Have you tried adding Volunteer to the belongsTo?
Is the other side of the relationship mapped using hasMany? There are
times when I don't want to map both sides and I've had some odd things
happen (of course, I don't have an example off hand), so I've gotten
into the habit of mapping both sides of relationships.
Scott
--
-------------------------------------------------
Scott Vlaminck // sc...@refactr.com
Refactr LLC // http://refactr.com
mobile // 612-386-9382
-------------------------------------------------
It's sometimes annoying, but that's been my experience so far. My
guess is that GORM can get a little confused if things aren't mapped
from both sides because it has to try to figure out what you want
without much information.
Your example with working and not-working solutions would be a good
one to post to the Grails User list as well, to see other people's
reaction.
Scott
--
-------------------------------------------------
Scott Vlaminck // sc...@refactr.com
Refactr LLC // http://refactr.com
mobile // 612-386-9382
-------------------------------------------------
class EventRoleTests extends GroovyTestCase {
void testSaveEventRole() {
def e = new Event(name:'eventName').save()
def p = new PositionObj(name:'positionName').save()
def er = new EventRole(event:e, position:p)
er.save(flush:true)
assert er.id
}
}
I tried a simple example with volunteer(nullable:true) and the test
worked - but the generated scaffolding didn't. Maybe there's a bug
with def eventRole = new EventRole(params) in the controller?
class EventRole {
static belongsTo = [Event, PositionObj]
Event event
PositionObj position
Volunteer volunteer
static constraints = {
volunteer(nullable:true)
}
}
Simple example attached: