Mapping hasMany relation and saving the related data
Asked Answered
S

1

6

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

Spidery answered 19/3, 2014 at 6:7 Comment(2)
Can you show me what your Question and Tag domains look like? Also your code for saving these domains would be helpful.Escutcheon
Try adding 'belongsTo' to the 'many' domain class. Also, please add your class/es definitionAngular
W
1

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.

Wassail answered 2/4, 2015 at 3:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.