{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/6023","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/6023/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/6023/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/6023/events","html_url":"https://github.com/sequelize/sequelize/issues/6023","id":158568803,"number":6023,"title":"Singularize `as` in foreign keys in To-Many associations (amendment of PR #5957)","user":{"login":"overlookmotel","id":557937,"avatar_url":"https://avatars.githubusercontent.com/u/557937?v=3","gravatar_id":"","url":"https://api.github.com/users/overlookmotel","html_url":"https://github.com/overlookmotel","followers_url":"https://api.github.com/users/overlookmotel/followers","following_url":"https://api.github.com/users/overlookmotel/following{/other_user}","gists_url":"https://api.github.com/users/overlookmotel/gists{/gist_id}","starred_url":"https://api.github.com/users/overlookmotel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overlookmotel/subscriptions","organizations_url":"https://api.github.com/users/overlookmotel/orgs","repos_url":"https://api.github.com/users/overlookmotel/repos","events_url":"https://api.github.com/users/overlookmotel/events{/privacy}","received_events_url":"https://api.github.com/users/overlookmotel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":34,"created_at":"2016-06-05T19:03:00Z","updated_at":"2016-06-12T13:21:46Z","closed_at":null,"body":"PR #5957 recently changed the names of foreign keys in associations where an `as` alias is specified.\r\n\r\nSo now: `Project.hasMany(User, {as: 'Workers'})` creates foreign key `WorkersId` rather than `UserId`.\r\n\r\nThis is great, but I do think the `as` should be singularized, so foreign key is `WorkerId`. This was already raised by @mickhansen in #5957, but I was too late to the party to get a comment in.\r\n\r\n`WorkersId` (plural), in my view, is not what the user would expect. It's inconsistent with the naming when no `as` alias is provided, and with the general Sequelize convention of singularizing/pluralizing. I can imagine it tripping people up quite often because it's counter-intuitive.\r\n\r\nYes, using `inflection` to singularize `as` could in some few cases produce the wrong result, but in those cases the user can override it by specifying `foreignKey`. Personally, I think that's preferable to having to specify `foreignKey` in all cases in order to maintain consistent naming.\r\n\r\nI'd be happy to make a PR for this, if there's agreement that this would be a good thing to do.\r\n\r\nWhat do you think @mickhansen @janmeier @sushantdhiman?"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/225431969","html_url":"https://github.com/sequelize/sequelize/issues/6023#issuecomment-225431969","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/6023","id":225431969,"user":{"login":"felixfbecker","id":10532611,"avatar_url":"https://avatars.githubusercontent.com/u/10532611?v=3","gravatar_id":"","url":"https://api.github.com/users/felixfbecker","html_url":"https://github.com/felixfbecker","followers_url":"https://api.github.com/users/felixfbecker/followers","following_url":"https://api.github.com/users/felixfbecker/following{/other_user}","gists_url":"https://api.github.com/users/felixfbecker/gists{/gist_id}","starred_url":"https://api.github.com/users/felixfbecker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felixfbecker/subscriptions","organizations_url":"https://api.github.com/users/felixfbecker/orgs","repos_url":"https://api.github.com/users/felixfbecker/repos","events_url":"https://api.github.com/users/felixfbecker/events{/privacy}","received_events_url":"https://api.github.com/users/felixfbecker/received_events","type":"User","site_admin":false},"created_at":"2016-06-12T13:21:46Z","updated_at":"2016-06-12T13:21:46Z","body":"@overlookmotel I agree. The `as` alias is for the _source_ model and should not be used when infering the foreign key on the _target_ model."}}
{"actor":{"display_login":"felixfbecker"}}