{"action":"closed","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/9530","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/9530/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/9530/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/9530/events","html_url":"https://github.com/sequelize/sequelize/issues/9530","id":331944867,"node_id":"MDU6SXNzdWUzMzE5NDQ4Njc=","number":9530,"title":"Incorrect or undocumented behaviour when `where` is an array","user":{"login":"LaurentVB","id":2806149,"node_id":"MDQ6VXNlcjI4MDYxNDk=","avatar_url":"https://avatars2.githubusercontent.com/u/2806149?v=4","gravatar_id":"","url":"https://api.github.com/users/LaurentVB","html_url":"https://github.com/LaurentVB","followers_url":"https://api.github.com/users/LaurentVB/followers","following_url":"https://api.github.com/users/LaurentVB/following{/other_user}","gists_url":"https://api.github.com/users/LaurentVB/gists{/gist_id}","starred_url":"https://api.github.com/users/LaurentVB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LaurentVB/subscriptions","organizations_url":"https://api.github.com/users/LaurentVB/orgs","repos_url":"https://api.github.com/users/LaurentVB/repos","events_url":"https://api.github.com/users/LaurentVB/events{/privacy}","received_events_url":"https://api.github.com/users/LaurentVB/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-13T10:59:49Z","updated_at":"2018-06-13T11:03:30Z","closed_at":"2018-06-13T11:03:30Z","author_association":"CONTRIBUTOR","body":"Hello, I just ran into a case for which I couldn't find any documentation and which seems a bit weird:\r\nWhen I pass an array as the `where` option in a `findAll` call, the query is generated but the field names are not mapped.\r\nE.g:\r\n\r\n```js\r\nconst User = sequelize.define('user', {\r\n  username: {\r\n    type: Sequelize.STRING,\r\n    field: 'user_name'\r\n  }\r\n});\r\n\r\nsequelize.sync()\r\n  .then(() => User.findAll({\r\n    where: [\r\n      { username: 'foobar' },\r\n      sequelize.literal('1 = 1')\r\n    ]\r\n  }));\r\n```\r\n\r\nI'd expect the generated query to use the mapped field name (`user_name`), but instead, it generates the following query, which fails: \r\n```sql\r\n    Executing (default): SELECT \"id\", \"user_name\" AS \"username\", \"created_at\", \"updated_at\", \"deleted_at\" FROM \"users\" AS \"user\" WHERE ((\"user\".\"deleted_at\" > '2018-06-13 10:53:35.054 +00:00' OR \"user\".\"deleted_at\" IS NULL) AND ((\"user\".\"username\" = 'foobar' AND 1 = 1)));\r\n```\r\n\r\nIronically, the error message does the mapping correctly 😄 \r\n\r\n```\r\n    Unhandled rejection SequelizeDatabaseError: column \"user_name\" does not exist\r\n```\r\nI guess the behaviour comes from this code: https://github.com/sequelize/sequelize/blob/b66f9ddc36720aef1523d677dbbfb9f257afa472/lib/utils.js#L183-L185\r\n\r\nI couldn't find any documentation about using an array as `where` option. It seems like for now, if that's the case, the array is properly transformed into WHERE clauses, but without attributes mapping.\r\nIf that's unsupported (but I found it used in one test about scope), how would you mix a \"regular\" `where` hash with some literal sql code?\r\n"}}
{"actor":{"display_login":"sushantdhiman"}}