Я использую sequenceize, я хочу, чтобы мой результат (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"
это не сработало. SurveyResult — это еще одна модель. Я получаю эту ошибку: "Неизвестный столбец \"SurveyResult.result.birthdate\" в \"списке полей\",






Вы должны сделать что-то вроде этого (это работает в том случае, если 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: []
}
})
}
попробуйте это:
attributes: [['forename', 'Vorname'], ['name', 'Nachname'] , ['SurveyResult.result.birthdate' , 'birthdate']],