Controller for a Bug:
this is the create method for a bug, I printed out bugInstance.activities
and it had my activity object in it
def create = {
def bugInstance = new Bug()
def activity = new Activity(description:"created")
bugInstance.properties = params
bugInstance.addToActivities(activity)
return [bugInstance: bugInstance]
}
Then I looked at the save method, and printed the exact same thing, and the result is null, so somehow it's lost the activity I created, and I have no idea why. Is this really the default behavior? Am I doing something really basic wrong, because there doesn't seem to be any reason such a simple piece of code wouldn't work.
def save = {
def bugInstance = new Bug(params)
println bugInstance.activities
if (bugInstance.save(flush: true)) {
flash.message = "${message(code: 'default.created.message', args: [message(code: 'bug.label', default: 'Bug'), bugInstance.id])}"
redirect(action: "show", id: bugInstance.id)
}
else {
render(view: "create", model: [bugInstance: bugInstance])
}
}
I know I can work around this by adding the activity in the save method, but why do I lose the activity from create() -> save()