{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/5942","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/5942/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/5942/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/5942/events","html_url":"https://github.com/sequelize/sequelize/issues/5942","id":156140333,"number":5942,"title":"Why aren't unique indexes in options.indexes added into uniqueKeys of model? ","user":{"login":"daleooo","id":6178534,"avatar_url":"https://avatars.githubusercontent.com/u/6178534?v=3","gravatar_id":"","url":"https://api.github.com/users/daleooo","html_url":"https://github.com/daleooo","followers_url":"https://api.github.com/users/daleooo/followers","following_url":"https://api.github.com/users/daleooo/following{/other_user}","gists_url":"https://api.github.com/users/daleooo/gists{/gist_id}","starred_url":"https://api.github.com/users/daleooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daleooo/subscriptions","organizations_url":"https://api.github.com/users/daleooo/orgs","repos_url":"https://api.github.com/users/daleooo/repos","events_url":"https://api.github.com/users/daleooo/events{/privacy}","received_events_url":"https://api.github.com/users/daleooo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-22T07:55:20Z","updated_at":"2016-05-23T00:30:06Z","closed_at":null,"body":"## Problem:\r\n\r\nWhen I define a model like this:\r\n\r\n```js\r\nvar User = sequelize.define('user', {\r\n  username: {\r\n    type: Sequelize.STRING,\r\n    unique: true\r\n  }\r\n});\r\n```\r\n\r\nunique index defined above will be added into uniqueKeys prop of user model, but when I define user like below:\r\n\r\n```js\r\nvar User = sequelize.define('user', {\r\n  username: Sequelize.STRING,\r\n}, {\r\nindexes: [{\r\n  unique: true,\r\n  fields: ['username']\r\n  }]\r\n});\r\n```\r\n\r\nunique index will not be added into uniqueKeys whether user.sync is called or not. \r\n\r\nIt is ok when I just need the UniqueConstraintError. But if I want to know the error fields which is returned with UniqueConstraintError object, I would be stuck. This is because UniqueConstraintError's fields prop depends on uniqueKeys of model.\r\n\r\n## Expect: \r\n\r\nAdd options.indexes to uniqueKeys when model.refreshAttributes() is called.\r\n\r\nBTW, I use sequelize 3.23.2(which is latest version in npm).\r\n\r\nThanks"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/220866098","html_url":"https://github.com/sequelize/sequelize/issues/5942#issuecomment-220866098","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/5942","id":220866098,"user":{"login":"daleooo","id":6178534,"avatar_url":"https://avatars.githubusercontent.com/u/6178534?v=3","gravatar_id":"","url":"https://api.github.com/users/daleooo","html_url":"https://github.com/daleooo","followers_url":"https://api.github.com/users/daleooo/followers","following_url":"https://api.github.com/users/daleooo/following{/other_user}","gists_url":"https://api.github.com/users/daleooo/gists{/gist_id}","starred_url":"https://api.github.com/users/daleooo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daleooo/subscriptions","organizations_url":"https://api.github.com/users/daleooo/orgs","repos_url":"https://api.github.com/users/daleooo/repos","events_url":"https://api.github.com/users/daleooo/events{/privacy}","received_events_url":"https://api.github.com/users/daleooo/received_events","type":"User","site_admin":false},"created_at":"2016-05-23T00:30:06Z","updated_at":"2016-05-23T00:30:06Z","body":"Yep, it's good. Add unique indexes into options.indexes and make unique indexes in uniqueKeys, attributes, and options.indexes consist with each other. Or adding all indexes into options.indexes and changing some code in function which throw unique constraint error solve this problem either. In the later way, uniqueKeys is redundant. Can I think like this way?"}}
{"actor":{"display_login":"daleooo"}}