I'm using Grails 1.2 and have the following many-to-many relationship setup:
class Employee {
static belongsTo = Store
static hasMany = [stores:Store]
}
class Store {
static hasMany = [employees:Employee]
}
I seed some data in Bootstrap.groovy:
store1.addToEmployees(employee1).save()
store1.addToEmployees(employee2).save()
store1.addToEmployees(employee3).save()
This results in the following DB data:
| store_employees |
----------------------------------
| store_id | employee_id |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
----------------------------------
Next, I try to remove a single employee from the store:
store.removeFromEmployees(employee1).save()
This results in all employees getting removed. Did I setup the relationship wrong or something?