{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3796","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3796/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3796/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3796/events","html_url":"https://github.com/sequelize/sequelize/issues/3796","id":80462944,"number":3796,"title":"N:M Association naming","user":{"login":"fourpixels","id":6096926,"avatar_url":"https://avatars.githubusercontent.com/u/6096926?v=3","gravatar_id":"","url":"https://api.github.com/users/fourpixels","html_url":"https://github.com/fourpixels","followers_url":"https://api.github.com/users/fourpixels/followers","following_url":"https://api.github.com/users/fourpixels/following{/other_user}","gists_url":"https://api.github.com/users/fourpixels/gists{/gist_id}","starred_url":"https://api.github.com/users/fourpixels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fourpixels/subscriptions","organizations_url":"https://api.github.com/users/fourpixels/orgs","repos_url":"https://api.github.com/users/fourpixels/repos","events_url":"https://api.github.com/users/fourpixels/events{/privacy}","received_events_url":"https://api.github.com/users/fourpixels/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-25T09:19:34Z","updated_at":"2015-05-26T11:38:38Z","closed_at":null,"body":"I have different associations and I can't figure out the naming of the fields.. For example:\r\n\r\n```js\r\nAnswer.belongsToMany(models.Question, {\r\n    through: models.QuestionToAnswer,\r\n    foreignKey: 'answer_id'\r\n});\r\n```\r\n\r\nThis generates question to answer table, with `question_id` and `answer_id` (I assume because I have both my models underscored with `id` as primary).\r\n\r\nIf I try to use what's in the docs (http://sequelize.readthedocs.org/en/latest/docs/associations/#naming-strategy) it simply does nothing:\r\n\r\n```js\r\nAnswer.belongsToMany(models.Question, {\r\n    through: models.QuestionToAnswer,\r\n    foreignKey: 'answer_id', // it doesn't matter if this line is here or not\r\n    as: { singular: 'task', plural: 'tasks' }\r\n});\r\n```\r\n\r\nAgain I get the very same result. The most important here is that if I try N:M self-referencing association I get an error:\r\n\r\n```js\r\nResource.belongsToMany(Resource, {\r\n    through: models.SubResource,\r\n    foreignKey: 'main_id',\r\n    as: { singular: 'task', plural: 'tasks' }}\r\n});\r\n```\r\n\r\nResult:\r\n\r\n```js\r\n...\\node_modules\\sequelize\\lib\\utils.js:470\r\n    return (tableName1.toLowerCase() < tableName2.toLowerCase()) ? (tableName1\r\n                                                  ^\r\nTypeError: undefined is not a function\r\n    at Object.module.exports.combineTableNames ...\\node_modules\\sequelize\\lib\\utils.js:470:51)\r\n    at new module.exports.BelongsToMany (...\\node_modules\\sequelize\\lib\\associations\\belongs-to-many.js:36:36)\r\n    at Mixin.belongsToMany (...\\node_modules\\sequelize\\lib\\associations\\mixin.js:354:21)\r\n```\r\n\r\n\r\nUsing\r\n```js\r\n    //as: 'SubResource'\r\n```\r\nworks out, I get `addSubResource` (singular) into my model, and it puts `sub_resource_id` into db.\r\n\r\n```js\r\n    as: 'sub_id'\r\n```\r\nend up with `sub_id_id` into db, and `getSub_id` method in model.\r\n\r\nSo, uhm, is the documentation wrong, or I'm missing out something with those naming strategies - I cannot figure out what's the result on different associations..\r\n\r\nI guess the best way is to use `as: 'SubResources', so that I can get proper (plural) method in model, and work out property (`sub_resource_id` - **singular**).\r\n\r\nA little bit more detailed spec would be great. Something like this: http://stackoverflow.com/questions/22958683/how-to-implement-many-to-many-association-in-sequelize"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/105495601","html_url":"https://github.com/sequelize/sequelize/issues/3796#issuecomment-105495601","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3796","id":105495601,"user":{"login":"fourpixels","id":6096926,"avatar_url":"https://avatars.githubusercontent.com/u/6096926?v=3","gravatar_id":"","url":"https://api.github.com/users/fourpixels","html_url":"https://github.com/fourpixels","followers_url":"https://api.github.com/users/fourpixels/followers","following_url":"https://api.github.com/users/fourpixels/following{/other_user}","gists_url":"https://api.github.com/users/fourpixels/gists{/gist_id}","starred_url":"https://api.github.com/users/fourpixels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fourpixels/subscriptions","organizations_url":"https://api.github.com/users/fourpixels/orgs","repos_url":"https://api.github.com/users/fourpixels/repos","events_url":"https://api.github.com/users/fourpixels/events{/privacy}","received_events_url":"https://api.github.com/users/fourpixels/received_events","type":"User","site_admin":false},"created_at":"2015-05-26T11:38:38Z","updated_at":"2015-05-26T11:38:38Z","body":"Well I've tried with `as: 'Subresources'`, and I only get `getSubresources` method (singular is missing).. As far as I can see in the code:\r\n\r\n```js\r\nthis.accessors = {\r\n      get: 'get' + plural,\r\n      set: 'set' + plural,\r\n      addMultiple: 'add' + plural,\r\n      add: 'add' + singular,\r\n      create: 'create' + singular,\r\n      remove: 'remove' + singular,\r\n      removeMultiple: 'remove' + plural,\r\n      hasSingle: 'has' + singular,\r\n      hasAll: 'has' + plural\r\n    };\r\n```"}}