Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = (sequelize, DataTypes) => {
- const Content = sequelize.define('Content', {
- title: {
- type: DataTypes.STRING,
- allowNull: false,
- },
- description: {
- type: DataTypes.STRING,
- allowNull: false,
- },
- duration: {
- type: DataTypes.INTEGER,
- allowNull: false,
- },
- thumbnail: {
- type: DataTypes.STRING,
- allowNull: false,
- },
- visibility: {
- type: DataTypes.ENUM,
- values: ['private', 'friends', 'public'],
- defaultValue: 'private',
- },
- uid: {
- type: DataTypes.STRING,
- allowNull: false,
- },
- created: {
- type: DataTypes.DATE,
- allowNull: false,
- defaultValue: sequelize.literal('CURRENT_TIMESTAMP'),
- },
- }, {
- tableName: 'contents',
- freezeTableName: true,
- timestamps: false,
- });
- Content.associate = (models) => {
- Content.belongsTo(models.User, {
- foreignKey: {
- name: 'user_id',
- allowNull: false,
- },
- onDelete: 'CASCADE',
- });
- Content.hasMany(models.Like, {
- foreignKey: {
- name: 'content_id',
- allowNull: false,
- },
- });
- };
- Content.prototype.toJSON = function () {
- // Return a shallow clone so toJSON method of the nested models can be called recursively.
- return Object.assign({}, this.get());
- };
- return Content;
- };
Advertisement
Add Comment
Please, Sign In to add comment