{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/6847","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/6847/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/6847/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/6847/events","html_url":"https://github.com/sequelize/sequelize/issues/6847","id":188987412,"number":6847,"title":"Questions about associate and distinct","user":{"login":"gzlock","id":2311740,"avatar_url":"https://avatars.githubusercontent.com/u/2311740?v=3","gravatar_id":"","url":"https://api.github.com/users/gzlock","html_url":"https://github.com/gzlock","followers_url":"https://api.github.com/users/gzlock/followers","following_url":"https://api.github.com/users/gzlock/following{/other_user}","gists_url":"https://api.github.com/users/gzlock/gists{/gist_id}","starred_url":"https://api.github.com/users/gzlock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzlock/subscriptions","organizations_url":"https://api.github.com/users/gzlock/orgs","repos_url":"https://api.github.com/users/gzlock/repos","events_url":"https://api.github.com/users/gzlock/events{/privacy}","received_events_url":"https://api.github.com/users/gzlock/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-13T19:01:15Z","updated_at":"2016-11-13T19:20:14Z","closed_at":"2016-11-13T19:03:17Z","body":"__Dialect:__ mysql\r\n__Database version:__ 5.7.5\r\n__Sequelize version:__ 3.*\r\n\r\n__Define__\r\n```\r\nuser = sequelize.define('user', {username: Sequelize.STRING});\r\nmessage  = sequelize.define('message', {content: Sequelize.TEXT});\r\nmessage.belongsTo(user, {as:'to', foreignKey: 'toUserId'});\r\nmessage.belongsTo(user, {as:'from', foreignKey: 'fromUserId'});\r\n```\r\n__Fill data__\r\nuserA and userB both send two messages to userC\r\n```\r\nuser.create({username: 'userA'});\r\nuser.create({username: 'userB'});\r\nuser.create({username: 'userC'});\r\nmessage.create({content: 'message 1',fromUserId: 1, toUserId: 3});\r\nmessage.create({content: 'message 2',fromUserId: 2, toUserId: 3});\r\nmessage.create({content: 'message 3',fromUserId: 1, toUserId: 3});\r\nmessage.create({content: 'message 4',fromUserId: 2, toUserId: 3});\r\n```\r\n\r\n__How to do ?__\r\nMerge the message records from the same user, like this\r\n```\r\n[\r\n    {content: 'message 3', from: {username: 'userA'}, createdAt: 'blablabla' ...},\r\n    {content: 'message 4', from: {username: 'userB'}, createdAt: 'blablabla' ...}\r\n]\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/260205986","html_url":"https://github.com/sequelize/sequelize/issues/6847#issuecomment-260205986","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/6847","id":260205986,"user":{"login":"gzlock","id":2311740,"avatar_url":"https://avatars.githubusercontent.com/u/2311740?v=3","gravatar_id":"","url":"https://api.github.com/users/gzlock","html_url":"https://github.com/gzlock","followers_url":"https://api.github.com/users/gzlock/followers","following_url":"https://api.github.com/users/gzlock/following{/other_user}","gists_url":"https://api.github.com/users/gzlock/gists{/gist_id}","starred_url":"https://api.github.com/users/gzlock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gzlock/subscriptions","organizations_url":"https://api.github.com/users/gzlock/orgs","repos_url":"https://api.github.com/users/gzlock/repos","events_url":"https://api.github.com/users/gzlock/events{/privacy}","received_events_url":"https://api.github.com/users/gzlock/received_events","type":"User","site_admin":false},"created_at":"2016-11-13T19:20:14Z","updated_at":"2016-11-13T19:20:14Z","body":"@felixfbecker  The request is i can't found about 'DISTINCT' usage in the doc website"}}
{"actor":{"display_login":"gzlock"}}