JiniKJohny
JiniKJohny

Reputation: 1182

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

Upvotes: 6

Views: 129

Answers (1)

vivwilfer
vivwilfer

Reputation: 174

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.

Upvotes: 1

Related Questions