javascript Sequelize:模型大纲
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Sequelize:模型大纲相关的知识,希望对你有一定的参考价值。
module.exports = {
underscored: true,
timestamps: false,
};
const Sequelize = require("sequelize");
const defaultModelOptions = require("../helpers/defaultModelOptions");
const modelDefinition = {
attribute: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
},
secondAttribute: {
field: "second_attribute",
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: true,
},
};
// Use default options and overwrite if necessary
const modelOptions = Object.assign({}, defaultModelOptions, { timestamps: true });
module.exports = (sequelize) => {
const Model = sequelize.define("model", modelDefinition, modelOptions);
Model.associate = models => {
Model.belongsTo(models.other-model, {
foreignKey: "other_model_id",
});
Model.belongsToMany(models.other-model, {
through: "model_other-model",
foreignKey: "other-model_id",
});
};
return Model;
};
以上是关于javascript Sequelize:模型大纲的主要内容,如果未能解决你的问题,请参考以下文章
javascript Sequelize:模型和关联index.js文件
javascript 这是Sequelize用户模型,具有令牌授权。通用盐与密码一起存储。
Node.js学习13~基于node-sequelize的查询器,附代码举例
Sequelize 模型重复值检查
同步 sequelize 模型:sequelize.import() 不是函数(并且已弃用)
Sequelize 模型关联不会创建新列