Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping hasMany relation and saving the related data

I have two domain classes Question and Tag. Question has 'hasMany relation' with Tag.

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

from my UI how can i send the list of Tags into QuestionController and how can i save Question with relationship with Tag

like image 510
JayKay Avatar asked Mar 19 '14 06:03

JayKay


1 Answers

Your currently having static hasMany = [tags:Tag]

But i believe you might be storing it directly as a string

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

as opposed to

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

I skipped the looping through tag values to show you whats implied. Hope this helps.

like image 116
vivwilfer Avatar answered Oct 09 '22 13:10

vivwilfer