{"action":"closed","issue":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/2477","labels_url":"https://api.github.com/repos/phalcon/cphalcon/issues/2477/labels{/name}","comments_url":"https://api.github.com/repos/phalcon/cphalcon/issues/2477/comments","events_url":"https://api.github.com/repos/phalcon/cphalcon/issues/2477/events","html_url":"https://github.com/phalcon/cphalcon/issues/2477","id":34387522,"number":2477,"title":"Query Builder","user":{"login":"sp3c1","id":4508208,"avatar_url":"https://avatars.githubusercontent.com/u/4508208?v=3","gravatar_id":"","url":"https://api.github.com/users/sp3c1","html_url":"https://github.com/sp3c1","followers_url":"https://api.github.com/users/sp3c1/followers","following_url":"https://api.github.com/users/sp3c1/following{/other_user}","gists_url":"https://api.github.com/users/sp3c1/gists{/gist_id}","starred_url":"https://api.github.com/users/sp3c1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sp3c1/subscriptions","organizations_url":"https://api.github.com/users/sp3c1/orgs","repos_url":"https://api.github.com/users/sp3c1/repos","events_url":"https://api.github.com/users/sp3c1/events{/privacy}","received_events_url":"https://api.github.com/users/sp3c1/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phalcon/cphalcon/labels/Not%20a%20bug","name":"Not a bug","color":"02e10c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-05-27T16:09:42Z","updated_at":"2015-08-28T21:45:04Z","closed_at":"2015-08-28T21:45:04Z","body":"Have a bit of a problem with Query builder from Models Manager\r\n\r\nWe are creating query for listing, and everything works fine, till we get to the WHERE\r\n\r\n```\r\nSELECT \r\n    u.id AS id, \r\n    u.email AS email, \r\n    u.username AS username,\r\n    u.active AS active, \r\n    u.first_name AS name,\r\n    u.last_name AS surname, \r\n    ur.name AS role_id \r\nFROM \r\n     [Fml\\Models\\Entities\\User] AS [u] JOIN \r\n     [Fml\\Models\\Entities\\UserRole] AS [ur] ON u.role_id = ur.id \r\nWHERE  \r\n      u.id = 43 \r\n```\r\nwe get the\r\n```\r\nSQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous\r\n```\r\nBut in the same query ORDER BY  u.id works just fine. Am I schizophrenic or is it a bug? ;]\r\n\r\nAnd yes, it was passed as  \r\n```\r\n->where(\" u.id = 43 \"); \r\n```\r\njust for test\r\n\r\n----\r\n\r\nNow we found workaround, but the problem remains. I guess alias that is created in SELECT building take some part in building the WHERE which is  A VERY BAD IDEA imo. \r\n\r\nSo when in SELECT \r\n```\r\nu.id as id\r\n```\r\nIs changed to \r\n```\r\nu.id as uid\r\n```\r\nIt starts to work magically.\r\n\r\nAlso u.id works now on WHERE and GROUP BY\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/2364878-query-builder?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F50707&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"}}