{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/1724","repository_url":"https://api.github.com/repos/tgriesser/knex","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/1724/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/1724/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/1724/events","html_url":"https://github.com/tgriesser/knex/issues/1724","id":181326539,"number":1724,"title":"Grouped chain \"where\" method doesn't work well with arrow function","user":{"login":"vietthang","id":1080481,"avatar_url":"https://avatars.githubusercontent.com/u/1080481?v=3","gravatar_id":"","url":"https://api.github.com/users/vietthang","html_url":"https://github.com/vietthang","followers_url":"https://api.github.com/users/vietthang/followers","following_url":"https://api.github.com/users/vietthang/following{/other_user}","gists_url":"https://api.github.com/users/vietthang/gists{/gist_id}","starred_url":"https://api.github.com/users/vietthang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vietthang/subscriptions","organizations_url":"https://api.github.com/users/vietthang/orgs","repos_url":"https://api.github.com/users/vietthang/repos","events_url":"https://api.github.com/users/vietthang/events{/privacy}","received_events_url":"https://api.github.com/users/vietthang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-06T05:18:10Z","updated_at":"2016-10-06T08:15:24Z","closed_at":null,"body":"From official documentation:\r\n\r\n```\r\nknex('users').where(function() {\r\n  this.where('id', 1).orWhere('id', '>', 10)\r\n}).orWhere({name: 'Tester'})\r\n```\r\n\r\nWhen I change the code to use arrow function instead of old function style, like this:\r\n\r\n```\r\nknex('users').where(() => {\r\n  this.where('id', 1).orWhere('id', '>', 10)\r\n}).orWhere({name: 'Tester'})\r\n```\r\n\r\nI got ```TypeError: Cannot read property 'where' of undefined``` on the second line. Seem like knex don't pass ```this``` to the function if it is arrow function.\r\n\r\nBeside with this behavior, I propose a new syntax:\r\n\r\n```\r\nknex('users').where((query) => {\r\n  return query.where('id', 1).orWhere('id', '>', 10)\r\n}).orWhere({name: 'Tester'})\r\n```\r\n\r\nwhich pass the old ```this``` as first parameter of the function so it feels more functional. Also we can keep ```this``` reference to keep backward compatible."},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/251896042","html_url":"https://github.com/tgriesser/knex/issues/1724#issuecomment-251896042","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/1724","id":251896042,"user":{"login":"elhigu","id":696345,"avatar_url":"https://avatars.githubusercontent.com/u/696345?v=3","gravatar_id":"","url":"https://api.github.com/users/elhigu","html_url":"https://github.com/elhigu","followers_url":"https://api.github.com/users/elhigu/followers","following_url":"https://api.github.com/users/elhigu/following{/other_user}","gists_url":"https://api.github.com/users/elhigu/gists{/gist_id}","starred_url":"https://api.github.com/users/elhigu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elhigu/subscriptions","organizations_url":"https://api.github.com/users/elhigu/orgs","repos_url":"https://api.github.com/users/elhigu/repos","events_url":"https://api.github.com/users/elhigu/events{/privacy}","received_events_url":"https://api.github.com/users/elhigu/received_events","type":"User","site_admin":false},"created_at":"2016-10-06T08:15:24Z","updated_at":"2016-10-06T08:15:24Z","body":"It already works like that "}}
{"actor":{"display_login":"elhigu"}}