从通过sequelize另一个模型添加属性和值
使用sequelize我想,我的结果(JSON)看起来像IM(见: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"
回答如下:
你必须做这样的事情(这工作,因为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: []
}
})
}
从通过sequelize另一个模型添加属性和值
使用sequelize我想,我的结果(JSON)看起来像IM(见: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"
回答如下:
你必须做这样的事情(这工作,因为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: []
}
})
}