Skip to content

Instantly share code, notes, and snippets.

@mickhansen
Created December 15, 2013 16:45
Show Gist options
  • Save mickhansen/7975176 to your computer and use it in GitHub Desktop.
Save mickhansen/7975176 to your computer and use it in GitHub Desktop.
Test-case for @dstanoev
var Sequelize = require('sequelize'),
sequelize = new Sequelize();
var User = sequelize.define('User', {}),
Post = sequelize.define('Post', {});
Post.belongsTo(User, {as: 'Creator', foreignKey: 'creator_id', foreignKeyConstraint: true});
User.hasMany(Post, {foreignKey: 'creator_id'});
User.hasMany(Post, {as: 'SharedPosts', joinTableName: 'SharedPosts', foreignKey: 'user_id', foreignKeyConstraint: true});
Post.hasMany(User, {as: 'SharedWithUsers', joinTableName: 'SharedPosts', foreignKey: 'post_id', foreignKeyConstraint: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment