{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3347","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3347/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3347/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3347/events","html_url":"https://github.com/sequelize/sequelize/issues/3347","id":61387944,"number":3347,"title":"Expose Model associations","user":{"login":"mdarveau","id":390071,"avatar_url":"https://avatars.githubusercontent.com/u/390071?v=3","gravatar_id":"","url":"https://api.github.com/users/mdarveau","html_url":"https://github.com/mdarveau","followers_url":"https://api.github.com/users/mdarveau/followers","following_url":"https://api.github.com/users/mdarveau/following{/other_user}","gists_url":"https://api.github.com/users/mdarveau/gists{/gist_id}","starred_url":"https://api.github.com/users/mdarveau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdarveau/subscriptions","organizations_url":"https://api.github.com/users/mdarveau/orgs","repos_url":"https://api.github.com/users/mdarveau/repos","events_url":"https://api.github.com/users/mdarveau/events{/privacy}","received_events_url":"https://api.github.com/users/mdarveau/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-14T03:43:07Z","updated_at":"2015-03-14T11:43:10Z","closed_at":null,"body":"Hi,\r\n\r\nI often have to do eager fetching of the same associations and I have to type the ```{ model: User, as: 'Manager'}``` multiple times as in:\r\n```\r\nLeague.findAll(\r\n      include: [\r\n        { model: User, as: 'Manager'}\r\n      ]\r\n    )\r\n```\r\nI found out that I could pass the return of ```League.belongsTo User, {as: 'Manager', foreignKey: { allowNull: false }}``` to the include and that would be accepted and processed correctly by sequelize. I'm not even sure this is truly supported so stop me if it's not.\r\n\r\nAssuming this is supported, it would be nice if this relation definition could be exposed in the model definition. I know I can always keep a reference to what was returned by the ```belongsTo``` call, but I found out that it's already in the model definition's ```associations``` property. However, it's not always in a key that matches the \"as\" parameter.\r\n\r\nWhat do you think if we added a ```getAssociation(asName)``` to ```Model``` so one could do:\r\n```\r\nLeague.findAll(\r\n      include: [\r\n        League.getAssociation('Manager')\r\n      ]\r\n    )\r\n```\r\nOr even better, something like the following:\r\n```\r\nLeague.findAll(\r\n      include: [\r\n        League.Manager\r\n      ]\r\n    )\r\n```\r\n... but I'm not sure of the possible conflicts\r\n\r\nWhat do you think? I could attempt a PR if you think this is a good idea.\r\n\r\nP.S.: All code are in coffeescript"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/80366171","html_url":"https://github.com/sequelize/sequelize/issues/3347#issuecomment-80366171","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3347","id":80366171,"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-03-14T11:43:10Z","updated_at":"2015-03-14T11:43:10Z","body":"`League.Manager = League.belongsTo(User, {as: 'Manager'})` should achieve what you need.\r\nWe allow include by association references (all association calls, belongsTo, hasMany etc, return an association reference)."}}