{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3095","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3095/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3095/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3095/events","html_url":"https://github.com/sequelize/sequelize/issues/3095","id":57238701,"number":3095,"title":"Querying on where association","user":{"login":"toaster33","id":2971768,"avatar_url":"https://avatars.githubusercontent.com/u/2971768?v=3","gravatar_id":"","url":"https://api.github.com/users/toaster33","html_url":"https://github.com/toaster33","followers_url":"https://api.github.com/users/toaster33/followers","following_url":"https://api.github.com/users/toaster33/following{/other_user}","gists_url":"https://api.github.com/users/toaster33/gists{/gist_id}","starred_url":"https://api.github.com/users/toaster33/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/toaster33/subscriptions","organizations_url":"https://api.github.com/users/toaster33/orgs","repos_url":"https://api.github.com/users/toaster33/repos","events_url":"https://api.github.com/users/toaster33/events{/privacy}","received_events_url":"https://api.github.com/users/toaster33/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-02-10T21:23:40Z","updated_at":"2015-02-13T08:18:49Z","closed_at":null,"body":"Curious if the implementation has changed on how to query on associations.  I created a test case that used to work on v2.0.0-rc8 but is currently not working on v2.0.0.  Was hoping for some clarity on how to adjust my code for the new changes.  Thanks for assistance.\r\n\r\n[Test case link](https://github.com/toaster33/sequelize/blob/master/test/integration/include.test.js)\r\n\r\nv2.0.0-rc8 query:\r\n```SELECT \r\n    `Company`.`id`,\r\n    `Company`.`name`,\r\n    `Company`.`createdAt`,\r\n    `Company`.`updatedAt`,\r\n    `Company`.`presidentId`,\r\n    `Company`.`departmentId`,\r\n    `President`.`id` AS `President.id`,\r\n    `President`.`name` AS `President.name`,\r\n    `President`.`createdAt` AS `President.createdAt`,\r\n    `President`.`updatedAt` AS `President.updatedAt`,\r\n    `Department`.`id` AS `Department.id`,\r\n    `Department`.`name` AS `Department.name`,\r\n    `Department`.`createdAt` AS `Department.createdAt`,\r\n    `Department`.`updatedAt` AS `Department.updatedAt`,\r\n    `Department`.`leadId` AS `Department.leadId`,\r\n    `Department.Lead`.`id` AS `Department.Lead.id`,\r\n    `Department.Lead`.`name` AS `Department.Lead.name`,\r\n    `Department.Lead`.`createdAt` AS `Department.Lead.createdAt`,\r\n    `Department.Lead`.`updatedAt` AS `Department.Lead.updatedAt`\r\nFROM\r\n    `Companies` AS `Company`\r\n        LEFT OUTER JOIN\r\n    `Users` AS `President` ON `Company`.`presidentId` = `President`.`id`\r\n        LEFT OUTER JOIN\r\n    `Departments` AS `Department` ON `Company`.`departmentId` = `Department`.`id`\r\n        LEFT OUTER JOIN\r\n    `Users` AS `Department.Lead` ON `Department`.`leadId` = `Department.Lead`.`id`\r\nWHERE\r\n    (`President`.`name` = 'OurLead'\r\n        OR `Department.Lead`.`name` = 'OurLead');\r\n```\r\n\r\nv2.0.0 query:\r\n```SELECT \r\n    `Company`.`id`,\r\n    `Company`.`name`,\r\n    `Company`.`createdAt`,\r\n    `Company`.`updatedAt`,\r\n    `Company`.`presidentId`,\r\n    `Company`.`departmentId`,\r\n    `President`.`id` AS `President.id`,\r\n    `President`.`name` AS `President.name`,\r\n    `President`.`createdAt` AS `President.createdAt`,\r\n    `President`.`updatedAt` AS `President.updatedAt`,\r\n    `Department`.`id` AS `Department.id`,\r\n    `Department`.`name` AS `Department.name`,\r\n    `Department`.`createdAt` AS `Department.createdAt`,\r\n    `Department`.`updatedAt` AS `Department.updatedAt`,\r\n    `Department`.`leadId` AS `Department.leadId`,\r\n    `Department.Lead`.`id` AS `Department.Lead.id`,\r\n    `Department.Lead`.`name` AS `Department.Lead.name`,\r\n    `Department.Lead`.`createdAt` AS `Department.Lead.createdAt`,\r\n    `Department.Lead`.`updatedAt` AS `Department.Lead.updatedAt`\r\nFROM\r\n    `Companies` AS `Company`\r\n        LEFT OUTER JOIN\r\n    `Users` AS `President` ON `Company`.`presidentId` = `President`.`id`\r\n        LEFT OUTER JOIN\r\n    `Departments` AS `Department` ON `Company`.`departmentId` = `Department`.`id`\r\n        LEFT OUTER JOIN\r\n    `Users` AS `Department.Lead` ON `Department`.`leadId` = `Department.Lead`.`id`\r\nWHERE\r\n    (`Company`.`President.name` = 'OurLead'\r\n        OR `Company`.`Department.Lead.name` = 'OurLead');\r\n```"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/74219441","html_url":"https://github.com/sequelize/sequelize/issues/3095#issuecomment-74219441","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3095","id":74219441,"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":"2015-02-13T08:18:49Z","updated_at":"2015-02-13T08:18:49Z","body":"Since it's possible to save story references, perhaps something like:\r\n\r\n```js\r\nwhere: {\r\n  $or: [\r\n    {$association: Company.associations.President, where: {\r\n      name: 'OurLead'\r\n    }}\r\n  ]\r\n}\r\n```"}}