3 const customUsersValidators = require('../helpers/custom-validators').users
5 module.exports = function (sequelize, DataTypes) {
6 const Author = sequelize.define('Author',
9 type: DataTypes.STRING,
12 usernameValid: function (value) {
13 const res = customUsersValidators.isUserUsernameValid(value)
14 if (res === false) throw new Error('Username is not valid.')
42 // ---------------------------------------------------------------------------
44 function associate (models) {
45 this.belongsTo(models.Pod, {
53 this.belongsTo(models.User, {
62 function findOrCreateAuthor (name, podId, userId, transaction, callback) {
64 callback = transaction
79 if (transaction) query.transaction = transaction
81 this.findOrCreate(query).asCallback(function (err, result) {
82 // [ instance, wasCreated ]
83 return callback(err, result[0])