I'm using Grails, and I have a domain model with multiple hasMany attributes to the same domain class, which looks like this:
static hasMany = [ posts : Post, likes : Post, dislikes : Post ]
The problem that I'm running into is that when I add something to the posts list, it also somehow makes it into the likes and dislikes lists. At least, that's how it looks when I iterate through each of those lists.
I think that the issue is that I also have the following relationship in my Post domain:
static belongsTo = [ contributer : Contributer ]
What is the best way of going about configuring these relationships to make my model work? Any suggestions?
@Wayne,
I tried using your test as well, and it passed successfully. So, the only thing that I can think of is that there is something wrong with my save method in my PostController. I have pasted the relavent code below (I am using the Spring Security Core plugin, and my Contributer class extends the User class that is created with that plugin):
@Secured(['IS_AUTHENTICATED_FULLY'])
def save = {
def props = [title:params.title, post:params.post, category:Category.get(params.category.id)]
def user = Contributer.get(springSecurityService.principal.id)
def postInstance = new Post(props)
postInstance.contributer = user
if (postInstance.save(flush: true)) {
flash.message = "${message(code: 'default.created.message', args: [message(code: 'post.label', default: 'Post'), postInstance.id])}"
redirect(action: "show", id: postInstance.id)
}
else {
render(view: "create", model: [postInstance: postInstance])
}
}
Is there anything that stands out here?