mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00
Add support of saving authors and authorship
This commit is contained in:
parent
44fd0a617b
commit
2f117a22cd
6 changed files with 240 additions and 3 deletions
43
lib/models/author.js
Normal file
43
lib/models/author.js
Normal file
|
@ -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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue