我有級聯的關聯,如模型: 調查>問題解答>選項Sequelize插入與關聯(級聯)
調查,有許多問題 問題有許多選項
當我創建調查我想用選項創建問題。 EX對象:
survey = {
title: title,
description: description,
Questions:[
{
question_type: 'Radio',
question: 'q1',
Options:[
{
option: 'o1'
},
{
option: 'o2'
}
]
}
]
}
當我創建使用該選項下面我得到的錯誤。
Unhandled rejection TypeError: Cannot read property 'getTableName' of undefined
我創建這個樣子的
models.Survey.create(survey,{
include: [models.Question,{include: [models.Option]}]
}).then(function() {
reply({success:1});
});
表scema
問:
QuestionId
SurveyId
我也有另外一個問題。如果我刪除了「選項」關聯,它將插入問題,但在創建「調查」之後它會輸入「NULL」作爲SurveyId。
你確定Survey是定義的嗎? – zerohero