diff options
author | Wu Cheng-Han | 2016-07-30 11:21:38 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2016-07-30 11:21:38 +0800 |
commit | 2f117a22cd21fa4fb67a3b2d687485795f86d030 (patch) | |
tree | 897902d9d55da45a4f7723f6ea69d6b04f10619b /lib/models/author.js | |
parent | 44fd0a617b3135720079f69dd522f6e25154ec36 (diff) |
Add support of saving authors and authorship
Diffstat (limited to 'lib/models/author.js')
-rw-r--r-- | lib/models/author.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/models/author.js b/lib/models/author.js new file mode 100644 index 00000000..0b0f149d --- /dev/null +++ b/lib/models/author.js @@ -0,0 +1,43 @@ +"use strict"; + +// external modules +var Sequelize = require("sequelize"); + +// core +var logger = require("../logger.js"); + +module.exports = function (sequelize, DataTypes) { + var Author = sequelize.define("Author", { + id: { + type: Sequelize.INTEGER, + primaryKey: true, + autoIncrement: true + }, + color: { + type: DataTypes.STRING + } + }, { + indexes: [ + { + unique: true, + fields: ['noteId', 'userId'] + } + ], + classMethods: { + associate: function (models) { + Author.belongsTo(models.Note, { + foreignKey: "noteId", + as: "note", + constraints: false + }); + Author.belongsTo(models.User, { + foreignKey: "userId", + as: "user", + constraints: false + }); + } + } + }); + + return Author; +};
\ No newline at end of file |