Can ORM sequelize have polymorphism? -
i have model named user. can extend model admin/mod user model? have found sequelize doc, didn't find out
yes, check out associations documentation, or more in scopes documentation.
from 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' });
Comments
Post a Comment