I just encountered a strange behaviour when deleting a object from a hasMany
Relation in grails 2.2.1.
Deleting is not working with:
def lessonInstance = Lesson.get(lessonId)
long id = Long.valueOf(taskId)
def task = Task.get(id)
lessonInstance.removeFromTasks(task)
While deleting is working with:
def lessonInstance = Lesson.get(lessonId)
long id = Long.valueOf(taskId)
def task = lessonInstance.tasks.find { it.id == id }
lessonInstance.removeFromTasks(task)
I expected both to work and I am now curious why the latter works and the first does not work. Here are the Domain classes envolved:
class Lesson{
static hasMany = [tasks:Task]
static hasOne = [skill:Skill]
static constraints = {
tasks(nullable: false, minSize: 1)
skill(nullable: true)
}
}
class Task extends Artefact{
Integer experiencePoints=0
Integer credits=0
static constraints = {
experiencePoints(blank: false, min: 0)
credits(blank: false, min: 0)
}
}
Thanks!