为什么要向结果集中添加额外的属性

时间:2018-07-28 04:01:34

标签: sequelize.js

我正在使用Sequelize-Mock,根据我的模型,我没想到会有id property or timestamps可以抑制这些吗?

mock.js

var UserMock = DBConnectionMock.define('users', {
    'Property1': 5,
    'Property2': 10,
    'Property3': 15,
    'Property4': 25
})


// From there we can start using it like a normal model
exports.getTotals = () => {
    return UserMock.findAll().then(r => r);
}

index.js console.log结果

[[ { Property1: 5,
    Property2: 10,
    Property3: 15,
    Property4: 25,
    id: 1,
    createdAt: '2018-07-28T03:54:14.442Z',
    updatedAt: '2018-07-28T03:54:14.442Z' } ]]

1 个答案:

答案 0 :(得分:1)

要禁用timeStamps设置,

timestamps: false

要防止创建主键id,请将其他任何列设置为主键,如

Property1: {
    type: Sequelize.STRING,
    primaryKey: true
}