我正在使用续集,我希望我的结果(JSON)像这样(请参阅:WantResult)。是否可以通过修改我的函数来完全找回该JSON?
这是我的功能:
try {
const mediImport = await User.findOne({
where: { Id: 1 },
// Select forename as Vorname, name as Nachname
attributes: [['forename', 'Vorname'], ['name', 'Nachname']],
include: {
model: SurveyResult,
attributes: ['result', 'result'] }
})
这是我的结果:
{
"Person": {
"Vorname": "Mustermann",
"Nachname": "Max",
"SurveyResult": {
"result": {
"birthdate": "01.01.1990",
"Sind Sie miteinander verheiratet?": "Ja",
"Waren Sie wegen Ihres Kinderwunsches bereits in ärztlicher Behandlung?": "Ja"
}
}
}
}
WantResult:但是我希望我的结果看起来像这样
Person": {
"Vorname": "Mustermann",
"Nachname": "Max",
"birthdate": "01.01.1990"
答案 0 :(得分:0)
您必须执行类似的操作(如果birthday
是SurveyResult
的属性,并且不在result
内,则可以使用此方法)
try {
const mediImport = await User.findOne({
where: { Id: 1 },
// Select forename as Vorname, name as Nachname
attributes: [
['forename', 'Vorname'],
['name', 'Nachname'],
[sequelize.literal('"SurveyResult"."birthdate"'), 'birthdate']
],
include: {
model: SurveyResult,
attributes: []
}
})
}