{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/5590","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/5590/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/5590/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/5590/events","html_url":"https://github.com/sequelize/sequelize/issues/5590","id":141019554,"number":5590,"title":"through: {attributes: []} does not remove attributes","user":{"login":"jmwilkinson","id":17836030,"avatar_url":"https://avatars.githubusercontent.com/u/17836030?v=3","gravatar_id":"","url":"https://api.github.com/users/jmwilkinson","html_url":"https://github.com/jmwilkinson","followers_url":"https://api.github.com/users/jmwilkinson/followers","following_url":"https://api.github.com/users/jmwilkinson/following{/other_user}","gists_url":"https://api.github.com/users/jmwilkinson/gists{/gist_id}","starred_url":"https://api.github.com/users/jmwilkinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmwilkinson/subscriptions","organizations_url":"https://api.github.com/users/jmwilkinson/orgs","repos_url":"https://api.github.com/users/jmwilkinson/repos","events_url":"https://api.github.com/users/jmwilkinson/events{/privacy}","received_events_url":"https://api.github.com/users/jmwilkinson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sequelize/sequelize/labels/bug","name":"bug","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-03-15T16:00:19Z","updated_at":"2016-03-17T06:44:50Z","closed_at":null,"body":"Setting through attributes to [] doesn't exclude the id columns from being selected.\r\n\r\nThe model query:\r\n```\r\ncomponentsPromise = models.Component.findAll({\r\n    include: [{\r\n        attributes: [],\r\n        model: models.Platform,\r\n        through: {\r\n            attributes: []\r\n        },\r\n        as: 'platforms',\r\n        where: {\r\n            id: {\r\n                in: ids\r\n            }\r\n        }\r\n    }],\r\n    group: ['component.id'],\r\n    having: ['COUNT(?) = ?', 'component.id', ids.length]\r\n})\r\n```\r\nDefining the association:\r\n\r\n```\r\nComponent.belongsToMany(Platform, {\r\n    through: 'platform_components',\r\n    as: 'platforms',\r\n    foreignKey: 'component_id',\r\n    otherKey: 'platform_id'\r\n});\r\n\r\nPlatform.belongsToMany(Component, {\r\n    through: 'platform_components',\r\n    as: 'components',\r\n    foreignKey: 'platform_id',\r\n    otherKey: 'component_id'\r\n});\r\n```\r\n\r\nThe result query:\r\n```\r\nSELECT\r\n  \"component\".\"id\",\r\n  \"component\".\"component_name\",\r\n  \"component\".\"component_type\",\r\n  \"component\".\"created_at\",\r\n  \"component\".\"updated_at\",\r\n  \"platforms.platform_components\".\"platform_id\"  AS \"platforms.platform_components.platform_id\",\r\n  \"platforms.platform_components\".\"component_id\" AS \"platforms.platform_components.component_id\"\r\nFROM \"components\" AS \"component\" INNER JOIN\r\n  (\"platform_components\" AS \"platforms.platform_components\" INNER JOIN \"platforms\" AS \"platforms\"\r\n      ON \"platforms\".\"id\" = \"platforms.platform_components\".\"platform_id\")\r\n    ON \"component\".\"id\" = \"platforms.platform_components\".\"component_id\" AND \"platforms\".\"id\" IN ('1', '2', '3')\r\nGROUP BY \"component\".\"id\", \"platforms.platform_components.platform_id\", \"platforms.platform_components.component_id\"\r\nHAVING COUNT('component.id') = 3;\r\n```\r\n\r\nThis is a major problem in postgres, as this query will fail because the group by must include the through table primary keys, which subsequently makes the query not function."},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/197731027","html_url":"https://github.com/sequelize/sequelize/issues/5590#issuecomment-197731027","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/5590","id":197731027,"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},"created_at":"2016-03-17T06:44:50Z","updated_at":"2016-03-17T06:44:50Z","body":"I'll mark as a bug untill i can verify either way."}}