I have a model named User. Can I extend another model Admin/mod from User model? I have found the sequelize doc, but i didn't find out
1
-
It's not truly supported at this time, but there are some ways to do similar constructs using Sequelize. The main discussion can be found at: github.com/sequelize/sequelize/issues/1307– iwasrobbedJun 3, 2017 at 19:21
Add a comment
|
1 Answer
Yes, check out the Associations documentation, or more fully in Scopes documentation.
From the docs:
this.Comment = this.sequelize.define('comment', {
title: Sequelize.STRING,
commentable: Sequelize.STRING,
commentable_id: Sequelize.INTEGER
});
this.Comment.prototype.getItem = function() {
return this['get' + this.get('commentable').substr(0, 1).toUpperCase() + this.get('commentable').substr(1)]();
};
this.Post.hasMany(this.Comment, {
foreignKey: 'commentable_id',
constraints: false,
scope: {
commentable: 'post'
}
});
this.Comment.belongsTo(this.Post, {
foreignKey: 'commentable_id',
constraints: false,
as: 'post'
});
this.Image.hasMany(this.Comment, {
foreignKey: 'commentable_id',
constraints: false,
scope: {
commentable: 'image'
}
});
this.Comment.belongsTo(this.Image, {
foreignKey: 'commentable_id',
constraints: false,
as: 'image'
});