Domanda

Sono perplesso da un comportamento che sto affrontando con il legame dei dati Grails.Inizerò con il codice del controller

def saveQuestion(){
   QuestionSurvey question = new QuestionSurvey();
   bindData(question, params);
   question.save(); 
}
.

Anche il dominio Questionsurvey è simile a

class QuestionSurvey {

    String questionText
    QuestionTypeSurvey questionType

    static hasMany = [options: QuestionOptionSurvey]

    static mapping = {  
        questionType enumType: 'ordinal'
    }

    static constraints = {}
}
.

Inoltre, il dominio Questionoptionsurvey sembra

class QuestionOptionSurvey {

    String optionText

    static belongsTo = [question: QuestionSurvey]

    static constraints = { }
}
.

Il vincolo penso che stia lavorando per tutte le proprietà ma non il campo "Opzioni" nel dominio DOMANDSURYSURY.L'errore che sto ricevendo è

TypeMismatchException: Provided id of the wrong type for class QuestionOptionSurvey.  

Expected class java.lang.Long got java.lang.String. So my question is how to get around   

this problem of binding params to a domain that has a field of type set of another domain 

class?
.

The params.options è un elenco di stringhe ad esempio ['option1', 'option2', 'option2'].

È stato utile?

Soluzione

Per collegare correttamente la proprietà / collezione options correttamente i parametri devono essere pubblicati con nomi di elementi come: options.optionText.Altrimenti si aspetterà che stai pubblicando ID e provano e individuano e individua il QuestionOptionSurvey corrispondente a quegli ID.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top