Friday 14 April 2017

Sequelize Join Models Include many to many

Say I have three models like this

var User = _define('user', {
  username: Sequelize.INTEGER
});
var UserPubCrawl = _define('userpubcrawl', {
  user_id: Sequelize.STRING(64), // the user
  bar_id: Sequelize.INTEGER // 1 to many
});

var Bars = _define('bar', {
  name:  type: Sequelize.STRING,
}

The relationships are one meal

User(one) --> UserPubCrawl (to many) --> Bars(to many)

So 1 user can have multiple pubcrawls to many bars for a particular pub crawl I want to find all the bars that "Simpson" went to.

Do i need to change the model definitions, if so please show me? What would the findAll Query look like?



via Robert I

No comments:

Post a Comment