Reputation: 13811
I have User
class:
class User {
static hasMany = [ project: Project ]
}
and Project
:
class Project {
static hasMany = [ users : User ]
static belongsTo = User
}
Anywhere in my code I can do this :
user.project
will return something like :
[project name]
I need a way to delete this relationship for any User
. How can I do that? I can find a user
project
using dynamic finders, criteria query so on, but how do I remove that relationship from a user
instance?
Very new to Grails.
Thanks in advance.
Upvotes: 0
Views: 56
Reputation: 66059
Use removeFrom
. Example:
user.removeFromProject(project)
In many-to-many relationships, you should manage the associations from the owning side: the one that is the target of the belongsTo
.
Note that it would probably be more clear to name the Project association "projects" instead of "project", since it's a many-to-many relationship.
Upvotes: 1