egg-sequelize的查询返回json的问题

我用findAll查询了分类的数据

const list = await model.findAll()

打印list如下:

[
  Category {
    dataValues: {
      id: 1,
      name: 'js',
      parentId: null,
      createdAt: '2020-03-15 12:35:49',
      updatedAt: '2020-03-15 12:35:49',
      deletedAt: null,
      children: [Array]
    },
    _previousDataValues: {
      id: 1,
      name: 'js',
      parentId: null,
      createdAt: '2020-03-15 12:35:49',
      updatedAt: '2020-03-15 12:35:49',
      deletedAt: null,
      children: [Array]
    },
    _changed: {},
    _modelOptions: {
      timestamps: true,
      validate: {},
      freezeTableName: false,
      underscored: false,
      paranoid: true,
      rejectOnEmpty: false,
      whereCollection: [Object],
      schema: null,
      schemaDelimiter: '',
      defaultScope: {},
      scopes: {},
      indexes: [],
      name: [Object],
      omitNull: false,
      sequelize: [Sequelize],
      hooks: {}
    },
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      include: [Array],
      includeNames: [Array],
      includeMap: [Object],
      includeValidated: true,
      attributes: [Array],
      raw: true
    },
    isNewRecord: false,
    children: [ [Category] ]
  },
  Category {
    dataValues: {
      id: 3,
      name: 'css',
      parentId: null,
      createdAt: '2020-06-12 01:00:39',
      updatedAt: '2020-06-12 01:00:39',
      deletedAt: null,
      children: []
    },
    _previousDataValues: {
      id: 3,
      name: 'css',
      parentId: null,
      createdAt: '2020-06-12 01:00:39',
      updatedAt: '2020-06-12 01:00:39',
      deletedAt: null,
      children: []
    },
    _changed: {},
    _modelOptions: {
      timestamps: true,
      validate: {},
      freezeTableName: false,
      underscored: false,
      paranoid: true,
      rejectOnEmpty: false,
      whereCollection: [Object],
      schema: null,
      schemaDelimiter: '',
      defaultScope: {},
      scopes: {},
      indexes: [],
      name: [Object],
      omitNull: false,
      sequelize: [Sequelize],
      hooks: {}
    },
    _options: {
      isNewRecord: false,
      _schema: null,
      _schemaDelimiter: '',
      include: [Array],
      includeNames: [Array],
      includeMap: [Object],
      includeValidated: true,
      attributes: [Array],
      raw: true
    },
    isNewRecord: false,
    children: []
  }
]

然后我把list给ctx.body返回

ctx.body = list

打印的response中,list是正确的json,而不是上面的对象,json如下:

\[

{

"id": 1,

"name": "js",

"parentId": null,

"createdAt": "2020-03-15 12:35:49",

"updatedAt": "2020-03-15 12:35:49",

"deletedAt": null,

"children": \[

{

"id": 2,

"name": "ts",

"parentId": 1,

"createdAt": "2020-06-12 01:00:29",

"updatedAt": "2020-06-12 01:00:29",

"deletedAt": null,

"children": \[\],

"articles": \[\]

}

\]

},

{

"id": 3,

"name": "css",

"parentId": null,

"createdAt": "2020-06-12 01:00:39",

"updatedAt": "2020-06-12 01:00:39",

"deletedAt": null,

"children": \[\]

}

\]

为什么会不一样呢?还是sequelize对这个封装对象做了什么处理?

阅读 2.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题