{"action":"created","comment":{"url":"https://api.github.com/repos/sequelize/sequelize/pulls/comments/40173603","id":40173603,"diff_hunk":"@@ -298,6 +298,46 @@ var BelongsToMany = function(source, target, options) {\n \n util.inherits(BelongsToMany, Association);\n \n+BelongsToMany.prototype.get = function(instances, options) {\n+  var throughModel = this.throughModel;\n+\n+  var throughOptions = _.assign({\n+    where: _.set({}, this.foreignKey, {$in: _.pluck(instances, this.source.primaryKeyAttribute)}),\n+    logging: options.logging\n+  });\n+\n+  var association = this;\n+\n+  return throughModel.findAll(throughOptions).then(function (throughs) {\n+    var otherKey = association.otherKey\n+      , targetIds = _.chain(throughs).pluck(otherKey).uniq().value();\n+\n+    var targetOptions = _.chain({\n+      where: _.set({}, association.target.primaryKeyAttribute, {$in: targetIds})\n+    })\n+        .assign(association.target.$optClone(options))\n+        .omit(['include'])\n+        .value();\n+\n+    return Utils.Promise.join(throughs, _.isEmpty(targetIds) ? null : association.target.findAll(targetOptions));","path":"lib/associations/belongs-to-many.js","position":25,"original_position":25,"commit_id":"d96b9cf1e2cb3162b7c260baa630571d2c5fa422","original_commit_id":"d96b9cf1e2cb3162b7c260baa630571d2c5fa422","user":{"login":"mickhansen","id":699049,"avatar_url":"https://avatars.githubusercontent.com/u/699049?v=3","gravatar_id":"","url":"https://api.github.com/users/mickhansen","html_url":"https://github.com/mickhansen","followers_url":"https://api.github.com/users/mickhansen/followers","following_url":"https://api.github.com/users/mickhansen/following{/other_user}","gists_url":"https://api.github.com/users/mickhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/mickhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mickhansen/subscriptions","organizations_url":"https://api.github.com/users/mickhansen/orgs","repos_url":"https://api.github.com/users/mickhansen/repos","events_url":"https://api.github.com/users/mickhansen/events{/privacy}","received_events_url":"https://api.github.com/users/mickhansen/received_events","type":"User","site_admin":false},"body":"`UNION ALL` is almost the same as running a query per source, except that we don't need to roundtrip and setup connections.\r\n\r\nIt will still work with multiple targets for source as far as i can tell. The combination of `right_id` and `left_id` is still unique in belongsToMany when `unique` is true (which is the common case and the default).","created_at":"2015-09-23T06:18:51Z","updated_at":"2015-09-23T06:18:51Z","html_url":"https://github.com/sequelize/sequelize/pull/4525#discussion_r40173603","pull_request_url":"https://api.github.com/repos/sequelize/sequelize/pulls/4525","_links":{"self":{"href":"https://api.github.com/repos/sequelize/sequelize/pulls/comments/40173603"},"html":{"href":"https://github.com/sequelize/sequelize/pull/4525#discussion_r40173603"},"pull_request":{"href":"https://api.github.com/repos/sequelize/sequelize/pulls/4525"}}},"pull_request":{"url":"https://api.github.com/repos/sequelize/sequelize/pulls/4525","id":45221599,"html_url":"https://github.com/sequelize/sequelize/pull/4525","diff_url":"https://github.com/sequelize/sequelize/pull/4525.diff","patch_url":"https://github.com/sequelize/sequelize/pull/4525.patch","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/4525","number":4525,"state":"open","locked":false,"title":"implement #4376 - support for include:separate for belongsToMany","user":{"login":"yotamofek","id":1835307,"avatar_url":"https://avatars.githubusercontent.com/u/1835307?v=3","gravatar_id":"","url":"https://api.github.com/users/yotamofek","html_url":"https://github.com/yotamofek","followers_url":"https://api.github.com/users/yotamofek/followers","following_url":"https://api.github.com/users/yotamofek/following{/other_user}","gists_url":"https://api.github.com/users/yotamofek/gists{/gist_id}","starred_url":"https://api.github.com/users/yotamofek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yotamofek/subscriptions","organizations_url":"https://api.github.com/users/yotamofek/orgs","repos_url":"https://api.github.com/users/yotamofek/repos","events_url":"https://api.github.com/users/yotamofek/events{/privacy}","received_events_url":"https://api.github.com/users/yotamofek/received_events","type":"User","site_admin":false},"body":"Hey,\r\n\r\nImplements #4376 \r\n\r\nThis is my first attempt at contribution.\r\nPlease let me know if there are any bugs or anything missing.\r\n\r\nThanks,\r\nYotam.","created_at":"2015-09-16T20:42:33Z","updated_at":"2015-09-23T06:18:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f36b8ee10297105375f4428e59d7500d83df2dde","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sequelize/sequelize/pulls/4525/commits","review_comments_url":"https://api.github.com/repos/sequelize/sequelize/pulls/4525/comments","review_comment_url":"https://api.github.com/repos/sequelize/sequelize/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/4525/comments","statuses_url":"https://api.github.com/repos/sequelize/sequelize/statuses/d96b9cf1e2cb3162b7c260baa630571d2c5fa422","head":{"label":"yotamofek:belongs.to.many.separate","ref":"belongs.to.many.separate","sha":"d96b9cf1e2cb3162b7c260baa630571d2c5fa422","user":{"login":"yotamofek","id":1835307,"avatar_url":"https://avatars.githubusercontent.com/u/1835307?v=3","gravatar_id":"","url":"https://api.github.com/users/yotamofek","html_url":"https://github.com/yotamofek","followers_url":"https://api.github.com/users/yotamofek/followers","following_url":"https://api.github.com/users/yotamofek/following{/other_user}","gists_url":"https://api.github.com/users/yotamofek/gists{/gist_id}","starred_url":"https://api.github.com/users/yotamofek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yotamofek/subscriptions","organizations_url":"https://api.github.com/users/yotamofek/orgs","repos_url":"https://api.github.com/users/yotamofek/repos","events_url":"https://api.github.com/users/yotamofek/events{/privacy}","received_events_url":"https://api.github.com/users/yotamofek/received_events","type":"User","site_admin":false},"repo":{"id":42612192,"name":"sequelize","full_name":"yotamofek/sequelize","owner":{"login":"yotamofek","id":1835307,"avatar_url":"https://avatars.githubusercontent.com/u/1835307?v=3","gravatar_id":"","url":"https://api.github.com/users/yotamofek","html_url":"https://github.com/yotamofek","followers_url":"https://api.github.com/users/yotamofek/followers","following_url":"https://api.github.com/users/yotamofek/following{/other_user}","gists_url":"https://api.github.com/users/yotamofek/gists{/gist_id}","starred_url":"https://api.github.com/users/yotamofek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yotamofek/subscriptions","organizations_url":"https://api.github.com/users/yotamofek/orgs","repos_url":"https://api.github.com/users/yotamofek/repos","events_url":"https://api.github.com/users/yotamofek/events{/privacy}","received_events_url":"https://api.github.com/users/yotamofek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yotamofek/sequelize","description":"Sequelize is an easy-to-use multi sql dialect ORM for Node.js & io.js. It currently supports MySQL, MariaDB, SQLite, PostgreSQL and MSSQL.","fork":true,"url":"https://api.github.com/repos/yotamofek/sequelize","forks_url":"https://api.github.com/repos/yotamofek/sequelize/forks","keys_url":"https://api.github.com/repos/yotamofek/sequelize/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yotamofek/sequelize/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yotamofek/sequelize/teams","hooks_url":"https://api.github.com/repos/yotamofek/sequelize/hooks","issue_events_url":"https://api.github.com/repos/yotamofek/sequelize/issues/events{/number}","events_url":"https://api.github.com/repos/yotamofek/sequelize/events","assignees_url":"https://api.github.com/repos/yotamofek/sequelize/assignees{/user}","branches_url":"https://api.github.com/repos/yotamofek/sequelize/branches{/branch}","tags_url":"https://api.github.com/repos/yotamofek/sequelize/tags","blobs_url":"https://api.github.com/repos/yotamofek/sequelize/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yotamofek/sequelize/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yotamofek/sequelize/git/refs{/sha}","trees_url":"https://api.github.com/repos/yotamofek/sequelize/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yotamofek/sequelize/statuses/{sha}","languages_url":"https://api.github.com/repos/yotamofek/sequelize/languages","stargazers_url":"https://api.github.com/repos/yotamofek/sequelize/stargazers","contributors_url":"https://api.github.com/repos/yotamofek/sequelize/contributors","subscribers_url":"https://api.github.com/repos/yotamofek/sequelize/subscribers","subscription_url":"https://api.github.com/repos/yotamofek/sequelize/subscription","commits_url":"https://api.github.com/repos/yotamofek/sequelize/commits{/sha}","git_commits_url":"https://api.github.com/repos/yotamofek/sequelize/git/commits{/sha}","comments_url":"https://api.github.com/repos/yotamofek/sequelize/comments{/number}","issue_comment_url":"https://api.github.com/repos/yotamofek/sequelize/issues/comments{/number}","contents_url":"https://api.github.com/repos/yotamofek/sequelize/contents/{+path}","compare_url":"https://api.github.com/repos/yotamofek/sequelize/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yotamofek/sequelize/merges","archive_url":"https://api.github.com/repos/yotamofek/sequelize/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yotamofek/sequelize/downloads","issues_url":"https://api.github.com/repos/yotamofek/sequelize/issues{/number}","pulls_url":"https://api.github.com/repos/yotamofek/sequelize/pulls{/number}","milestones_url":"https://api.github.com/repos/yotamofek/sequelize/milestones{/number}","notifications_url":"https://api.github.com/repos/yotamofek/sequelize/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yotamofek/sequelize/labels{/name}","releases_url":"https://api.github.com/repos/yotamofek/sequelize/releases{/id}","created_at":"2015-09-16T20:40:59Z","updated_at":"2015-09-16T20:41:01Z","pushed_at":"2015-09-16T20:41:22Z","git_url":"git://github.com/yotamofek/sequelize.git","ssh_url":"git@github.com:yotamofek/sequelize.git","clone_url":"https://github.com/yotamofek/sequelize.git","svn_url":"https://github.com/yotamofek/sequelize","homepage":"http://sequelizejs.com","size":15821,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sequelize:master","ref":"master","sha":"abb9bd9635da7f4e9010697a182bba267c004eed","user":{"login":"sequelize","id":3591786,"avatar_url":"https://avatars.githubusercontent.com/u/3591786?v=3","gravatar_id":"","url":"https://api.github.com/users/sequelize","html_url":"https://github.com/sequelize","followers_url":"https://api.github.com/users/sequelize/followers","following_url":"https://api.github.com/users/sequelize/following{/other_user}","gists_url":"https://api.github.com/users/sequelize/gists{/gist_id}","starred_url":"https://api.github.com/users/sequelize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sequelize/subscriptions","organizations_url":"https://api.github.com/users/sequelize/orgs","repos_url":"https://api.github.com/users/sequelize/repos","events_url":"https://api.github.com/users/sequelize/events{/privacy}","received_events_url":"https://api.github.com/users/sequelize/received_events","type":"Organization","site_admin":false},"repo":{"id":790359,"name":"sequelize","full_name":"sequelize/sequelize","owner":{"login":"sequelize","id":3591786,"avatar_url":"https://avatars.githubusercontent.com/u/3591786?v=3","gravatar_id":"","url":"https://api.github.com/users/sequelize","html_url":"https://github.com/sequelize","followers_url":"https://api.github.com/users/sequelize/followers","following_url":"https://api.github.com/users/sequelize/following{/other_user}","gists_url":"https://api.github.com/users/sequelize/gists{/gist_id}","starred_url":"https://api.github.com/users/sequelize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sequelize/subscriptions","organizations_url":"https://api.github.com/users/sequelize/orgs","repos_url":"https://api.github.com/users/sequelize/repos","events_url":"https://api.github.com/users/sequelize/events{/privacy}","received_events_url":"https://api.github.com/users/sequelize/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sequelize/sequelize","description":"Sequelize is an easy-to-use multi sql dialect ORM for Node.js & io.js. It currently supports MySQL, MariaDB, SQLite, PostgreSQL and MSSQL.","fork":false,"url":"https://api.github.com/repos/sequelize/sequelize","forks_url":"https://api.github.com/repos/sequelize/sequelize/forks","keys_url":"https://api.github.com/repos/sequelize/sequelize/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sequelize/sequelize/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sequelize/sequelize/teams","hooks_url":"https://api.github.com/repos/sequelize/sequelize/hooks","issue_events_url":"https://api.github.com/repos/sequelize/sequelize/issues/events{/number}","events_url":"https://api.github.com/repos/sequelize/sequelize/events","assignees_url":"https://api.github.com/repos/sequelize/sequelize/assignees{/user}","branches_url":"https://api.github.com/repos/sequelize/sequelize/branches{/branch}","tags_url":"https://api.github.com/repos/sequelize/sequelize/tags","blobs_url":"https://api.github.com/repos/sequelize/sequelize/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sequelize/sequelize/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sequelize/sequelize/git/refs{/sha}","trees_url":"https://api.github.com/repos/sequelize/sequelize/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sequelize/sequelize/statuses/{sha}","languages_url":"https://api.github.com/repos/sequelize/sequelize/languages","stargazers_url":"https://api.github.com/repos/sequelize/sequelize/stargazers","contributors_url":"https://api.github.com/repos/sequelize/sequelize/contributors","subscribers_url":"https://api.github.com/repos/sequelize/sequelize/subscribers","subscription_url":"https://api.github.com/repos/sequelize/sequelize/subscription","commits_url":"https://api.github.com/repos/sequelize/sequelize/commits{/sha}","git_commits_url":"https://api.github.com/repos/sequelize/sequelize/git/commits{/sha}","comments_url":"https://api.github.com/repos/sequelize/sequelize/comments{/number}","issue_comment_url":"https://api.github.com/repos/sequelize/sequelize/issues/comments{/number}","contents_url":"https://api.github.com/repos/sequelize/sequelize/contents/{+path}","compare_url":"https://api.github.com/repos/sequelize/sequelize/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sequelize/sequelize/merges","archive_url":"https://api.github.com/repos/sequelize/sequelize/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sequelize/sequelize/downloads","issues_url":"https://api.github.com/repos/sequelize/sequelize/issues{/number}","pulls_url":"https://api.github.com/repos/sequelize/sequelize/pulls{/number}","milestones_url":"https://api.github.com/repos/sequelize/sequelize/milestones{/number}","notifications_url":"https://api.github.com/repos/sequelize/sequelize/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sequelize/sequelize/labels{/name}","releases_url":"https://api.github.com/repos/sequelize/sequelize/releases{/id}","created_at":"2010-07-22T07:11:11Z","updated_at":"2015-09-23T05:03:23Z","pushed_at":"2015-09-23T06:16:16Z","git_url":"git://github.com/sequelize/sequelize.git","ssh_url":"git@github.com:sequelize/sequelize.git","clone_url":"https://github.com/sequelize/sequelize.git","svn_url":"https://github.com/sequelize/sequelize","homepage":"http://sequelizejs.com","size":60924,"stargazers_count":4589,"watchers_count":4589,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1028,"mirror_url":null,"open_issues_count":536,"forks":1028,"open_issues":536,"watchers":4589,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sequelize/sequelize/pulls/4525"},"html":{"href":"https://github.com/sequelize/sequelize/pull/4525"},"issue":{"href":"https://api.github.com/repos/sequelize/sequelize/issues/4525"},"comments":{"href":"https://api.github.com/repos/sequelize/sequelize/issues/4525/comments"},"review_comments":{"href":"https://api.github.com/repos/sequelize/sequelize/pulls/4525/comments"},"review_comment":{"href":"https://api.github.com/repos/sequelize/sequelize/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sequelize/sequelize/pulls/4525/commits"},"statuses":{"href":"https://api.github.com/repos/sequelize/sequelize/statuses/d96b9cf1e2cb3162b7c260baa630571d2c5fa422"}}}}