Mise à jour des models mysql
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
const { DataTypes, Model } = require("sequelize");
|
||||
const sequelize = require("../../config/sequelize");
|
||||
|
||||
class Comment extends Model { }
|
||||
|
||||
const CommentModel = () => {
|
||||
Comment.init(
|
||||
{
|
||||
id: {
|
||||
autoIncrement: true,
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
body: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false
|
||||
},
|
||||
authorId: {
|
||||
type: DataTypes.STRING(24),
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: 'user',
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
articleId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
references: {
|
||||
model: 'article',
|
||||
key: 'id'
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'comment',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{
|
||||
name: "PRIMARY",
|
||||
unique: true,
|
||||
using: "BTREE",
|
||||
fields: [
|
||||
{ name: "id" },
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "authorId",
|
||||
using: "BTREE",
|
||||
fields: [
|
||||
{ name: "authorId" },
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "articleId",
|
||||
using: "BTREE",
|
||||
fields: [
|
||||
{ name: "articleId" },
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
);
|
||||
|
||||
Comment.prototype.toJSONFor = function () {
|
||||
return {
|
||||
id: this.id,
|
||||
body: this.body
|
||||
};
|
||||
};
|
||||
|
||||
return Comment;
|
||||
};
|
||||
|
||||
module.exports = CommentModel;
|
||||
Reference in New Issue
Block a user