summaryrefslogtreecommitdiff
path: root/lib/models/author.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/author.js')
-rw-r--r--lib/models/author.js43
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