{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/knex/issues/1815","repository_url":"https://api.github.com/repos/tgriesser/knex","labels_url":"https://api.github.com/repos/tgriesser/knex/issues/1815/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/knex/issues/1815/comments","events_url":"https://api.github.com/repos/tgriesser/knex/issues/1815/events","html_url":"https://github.com/tgriesser/knex/issues/1815","id":192886184,"number":1815,"title":"Incorrect checks @ building queries","user":{"login":"ts33kr","id":974318,"avatar_url":"https://avatars.githubusercontent.com/u/974318?v=3","gravatar_id":"","url":"https://api.github.com/users/ts33kr","html_url":"https://github.com/ts33kr","followers_url":"https://api.github.com/users/ts33kr/followers","following_url":"https://api.github.com/users/ts33kr/following{/other_user}","gists_url":"https://api.github.com/users/ts33kr/gists{/gist_id}","starred_url":"https://api.github.com/users/ts33kr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ts33kr/subscriptions","organizations_url":"https://api.github.com/users/ts33kr/orgs","repos_url":"https://api.github.com/users/ts33kr/repos","events_url":"https://api.github.com/users/ts33kr/events{/privacy}","received_events_url":"https://api.github.com/users/ts33kr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-01T15:58:58Z","updated_at":"2016-12-01T16:48:12Z","closed_at":null,"body":"In the builder code there are places where lodash.isObject is not properly used.\r\n\r\nThe thing is, per documentation, isObject will yield true for arrays, strings, functions et cetera.\r\nThe result is that orWhere _yields non-sense when array is passed_ in. (adds redundant AND clause to query)\r\n\r\n> Checks if value is the language type of Object. (e.g. arrays, functions, objects, regexes, new Number(0), and new String(''))\r\n\r\n```js\r\n  // Adds an `or where` clause to the query.\r\n  orWhere: function orWhere() {\r\n    this._bool('or');\r\n    const obj = arguments[0];\r\n    if(isObject(obj) && !isFunction(obj) && !(obj instanceof Raw)) {\r\n      return this.whereWrapped(function() {\r\n        for(const key in obj) {\r\n          this.andWhere(key, obj[key]);\r\n        }\r\n      });\r\n    }\r\n    return this.where.apply(this, arguments);\r\n  },\r\n```"},"comment":{"url":"https://api.github.com/repos/tgriesser/knex/issues/comments/264226260","html_url":"https://github.com/tgriesser/knex/issues/1815#issuecomment-264226260","issue_url":"https://api.github.com/repos/tgriesser/knex/issues/1815","id":264226260,"user":{"login":"ts33kr","id":974318,"avatar_url":"https://avatars.githubusercontent.com/u/974318?v=3","gravatar_id":"","url":"https://api.github.com/users/ts33kr","html_url":"https://github.com/ts33kr","followers_url":"https://api.github.com/users/ts33kr/followers","following_url":"https://api.github.com/users/ts33kr/following{/other_user}","gists_url":"https://api.github.com/users/ts33kr/gists{/gist_id}","starred_url":"https://api.github.com/users/ts33kr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ts33kr/subscriptions","organizations_url":"https://api.github.com/users/ts33kr/orgs","repos_url":"https://api.github.com/users/ts33kr/repos","events_url":"https://api.github.com/users/ts33kr/events{/privacy}","received_events_url":"https://api.github.com/users/ts33kr/received_events","type":"User","site_admin":false},"created_at":"2016-12-01T16:48:12Z","updated_at":"2016-12-01T16:48:12Z","body":"To make a simple example, having this:\r\n\r\n```js\r\n        var remotes = [\"a\", \"b\", \"c\"];\r\n        var locals = [\"a\", \"b\", \"c\"];\r\n\r\n        console.log(traces\r\n            .whereIn(\"local\", remotes)\r\n            .orWhereIn(\"remote\", locals)\r\n            .select().toString()\r\n        );\r\n```\r\n\r\nwe get the following\r\n\r\n```sql\r\nselect * from \"traces\" where \"local\" in ('a', 'b', 'c') or \"remote\" in ('a', 'b', 'c')\r\nand \"local\" in ('a', 'b', 'c') or \"remote\" in ('a', 'b', 'c')\r\n```\r\n\r\nnotice what goes on with adding \"AND\" that should not be there"}}
{"actor":{"display_login":"ts33kr"}}