sequelize模型中加进get方法后不管什么情况都会自动取值
如下,在模型中定义CreatedAtStr
字段,并且加了get
方法,
CreatedAtStr: {
type: DataTypes.STRING,
allowNull: true,
get () {
let time = this.getDataValue('CreatedAt') || ''
return time ? dateStr(time) : ''
}
}
在接口中获取的时候,该表在其他表的关联中,属性只取了Id
, 但获取结果中有CreatedAtStr
where: query,
include: [
{
model: Comments,
attributes: [
'Id'
]
}
]
求解
获取结果
"UserId": "e2420d70-a069-11e8-bde3-057bb13f44a3",
"Comments": [
{
"CreatedAtStr": "",
"Id": 4
},
{
"CreatedAtStr": "",
"Id": 5
},
{
"CreatedAtStr": "",
"Id": 6
},
{
"CreatedAtStr": "",
"Id": 7
}
]
2 回复
Anybady out there?0.0
= =