Mapping hasMany relationship and saving related data

I have two domain classes Question and Tag. The question is related to hasMany tag.

I am trying to save a question with some tags, but the error message "Could not convert the value of a property of type java.lang.String to the required type com.org.Tag for the property tag; the nested exception is java.lang.IllegalStateException: cannot convert a value of type [ java.lang.String] to the required type [com.org.Tag] for the property tag: no suitable editors found or conversion strategy "

from my user interface, how can I send a list of tags to QuestionController and how can I save a question with a relation with a tag

+6
source share
1 answer

Currently static hasMany = [tags: tag]

But I believe that you can store it directly as a string

questionInstance.tags = ['tag1', 'tag2',...] 

Unlike

 questionInstance.tags = [new Tag(name: tag1), new Tag(name: tag2),...] 

I skipped the missing tags to show you what is meant. Hope this helps.

+1
source

All Articles