Friday, February 27, 2009

Grails many-to-many

by Richard Vowles

I am sure others have come across this and figured out, but just in case Google (TM) wishes to index it, I had the problem trying to figure out how to remove an item from the many part of one side of a many to many collection.

Here it basically was:

static hasMany = [danceLevels:DanceLevel]
static belongsTo = DanceStyle

static hasMany = [danceStyles:DanceStyle]

So the key here is that you can only remove/delete from the side noted in the belongsTo - you cannot take a dance style and remove a specific dance level from it, you have to find the dance styles on the dance level and remove the style - otherwise Hibernate (although it recognizes the dirty collection) does not do anything about it. No matter how you stuff about the cascade maping.

No comments: