This is my domain model, the survey has many questions, and each question has many repsons:
class Survey { String name String customerName static hasMany = [questions: SurveyQuestion] static constraints = { } } class SurveyQuestion { String question static hasMany = [responses : SurveyQuestionResponse] static belongsTo = [survey: Survey] static constraints = { } } class SurveyQuestionResponse { String description static belongsTo = [question: SurveyQuestion] static constraints = { } }
In my controller, I have a method that takes the identifier for the survey, looks at it, then builds the question from another query parameter, tries to add the question to the poll and save it:
def addQuestion = { def question = new SurveyQuestion(question:params.question) def theSurvey = Survey.get(params.id) theSurvey.addToQuestions(question) //fails on this line theSurvey.save(flush:true) redirect(action: showSurvey, params:[id:theSurvey.id]) }
However, it fails and returns this:
No method signature: roosearch.Survey.addToQuestions () is applicable for argument types: (roosearch.SurveyQuestion) values: [roosearch.SurveyQuestion: null] Possible solutions: addToQuestions (java.lang.Object), getQuestions ()
I don’t quite understand what I'm doing wrong here, I tried various alternative ways to create a question, even creating an instance of one manually with a literal string, but it always gives the same error.
Can anyone advise me?
thanks
Jimmy source share