Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

sequelize delete

Posted at 2016-03-27 sequelize 

當你需要刪除一筆資料,但不要實際刪除資料,只想多一個欄位叫 deletedAt,並把刪除時間更新上去,sequelize 有提供這個功能,真的蠻實用的。

don’t delete database entries but set the newly added attribute deletedAt
to the current date (when deletion was done). paranoid will only work if
timestamps are enabled

1
2
3
4
5
6
7
8
9
10
11
12
13
var ContactUs = sequelize.define('ContactUs', {
name: DataTypes.STRING,
email: DataTypes.STRING,
phone: DataTypes.STRING,
content: DataTypes.TEXT,
},{
// 加這行
paranoid: true,
classMethods: {
associate: function(models){
}
}
});

資料來源
http://docs.sequelizejs.com/en/latest/docs/models-definition/

Share 

 Previous post: 物件宣告 Sails 多國語系 Next post: React Debug 小技巧 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo