Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var User = sequelize.define('user', {
- username: Sequelize.STRING,
- password: Sequelize.STRING
- });
- var Tag = sequelize.define('tag', {
- tag: Sequelize.STRING
- });
- var Post = sequelize.define('post', {
- comment: Sequelize.STRING,
- link_url: Sequelize.STRING,
- link_description: Sequelize.STRING,
- link_image: Sequelize.STRING,
- link_title: Sequelize.STRING,
- vote_count: Sequelize.INTEGER
- });
- var Category = sequelize.define('category', {
- name: Sequelize.STRING
- });
- Category.hasMany(Post);
- Post.belongsTo(Category);
- Post.belongsToMany(Tag, {through: 'tagpost'});
- Tag.belongsToMany(Post, {through: 'tagpost'});
- sequelize.sync();
- module.exports.User = User;
- module.exports.Tag = Tag;
- module.exports.Post = Post;
- module.exports.Category = Category;
- var db = require('../db/schema');
- db.Category.create({
- name: category
- })
- .then(function(category) {
- return category.createPost({
- comment: comment,
- link_url: link_url,
- link_description: link_description,
- link_image: link_image,
- link_title: link_title,
- vote_count: 0
- })
- })
- .then(function(post) {
- post.createTag({tag: tags});
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement