I have been using Grails addTo and removeFrom dynamic methods and they are awesome, Usually I use them in following way
String id =params.quizId
Quiz quizInstance = Quiz.get(Long.parseLong(id))// **1**
for( String q in params.questionCheckBox)
{
Question question = Question.get(Long.parseLong(q))//**2**
quizInstance.addToQuestions(question)//**3**
}
Being a person who used to work on java I visualize this piece of code as following three steps
- run a select query to get quizInstance
- run a select query to get question
- run an insert query to insert questions in QUIZ_QUESTION table
I do see that third step only requires just quiz id and and Question id then why to perform first two steps. Is there an "addTo" kind of static method which I can use to say Quiz.addToQuestionAndQuiz(questionId,QuizId)
Please correct me if I am wrong in assuming the way things will go on db side.
Also is there a way to add a list of values dirctly using addTo method or must I use a for loop?