Created
December 15, 2013 17:26
-
-
Save mickhansen/7975651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Sequelize = require('sequelize'), | |
sequelize = new Sequelize('sequelize_test', 'sequelize_test', 'YDLvjZJv9GdvbM8G', { | |
syncOnAssociation: false, | |
logging: console.log | |
}); | |
var User = sequelize.define('User', {}), | |
Post = sequelize.define('Post', {}), | |
SharedPosts = sequelize.define('SharedPosts', {}) | |
Post.belongsTo(User, {as: 'Creator', foreignKey: 'creator_id', foreignKeyConstraint: true}); | |
User.hasMany(Post, {foreignKey: 'creator_id'}); | |
User.hasMany(Post, {as: 'SharedPosts', joinTableModel: SharedPosts, foreignKey: 'user_id'}); // , foreignKey: 'user_id', foreignKeyConstraint: true | |
Post.hasMany(User, {as: 'SharedWithUsers', joinTableModel: SharedPosts, foreignKey: 'post_id'}); // , foreignKey: 'post_id', foreignKeyConstraint: true | |
sequelize.sync({force: true}).done(function (err) { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment