{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/17226","labels_url":"https://api.github.com/repos/rails/rails/issues/17226/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/17226/comments","events_url":"https://api.github.com/repos/rails/rails/issues/17226/events","html_url":"https://github.com/rails/rails/issues/17226","id":45449983,"number":17226,"title":"Rails where query should see value is an enum and convert a string","user":{"login":"justin808","id":1118459,"avatar_url":"https://avatars.githubusercontent.com/u/1118459?v=3","gravatar_id":"","url":"https://api.github.com/users/justin808","html_url":"https://github.com/justin808","followers_url":"https://api.github.com/users/justin808/followers","following_url":"https://api.github.com/users/justin808/following{/other_user}","gists_url":"https://api.github.com/users/justin808/gists{/gist_id}","starred_url":"https://api.github.com/users/justin808/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justin808/subscriptions","organizations_url":"https://api.github.com/users/justin808/orgs","repos_url":"https://api.github.com/users/justin808/repos","events_url":"https://api.github.com/users/justin808/events{/privacy}","received_events_url":"https://api.github.com/users/justin808/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2014-10-10T06:21:07Z","updated_at":"2015-02-18T16:43:57Z","closed_at":"2014-10-11T14:38:11Z","body":"Suppose you have this situation:\r\n\r\n```ruby\r\nMyModel.where(some_enum: \"enum_value\")\r\n```\r\n\r\nWell, that currently doesn't work. You have to do this:\r\n\r\n```ruby\r\nMyModel.where(some_enum: some_enums[\"enum_value\"])\r\n```\r\nThat is so that \"enum_value\" is converted to the proper integer value.\r\n\r\nEven worse, the first query currently does not throw an error and converts the string (any string) to an integer value of zero!\r\n\r\nHere's an actual console trace showing this:\r\n\r\n```\r\n[17] (pry) main: 0> Manager.where(dominant_product_type: \"hedge_fund\").count\r\n   (8.3ms)  SELECT COUNT(*) FROM \"managers\"  WHERE \"managers\".\"dominant_product_type\" = 0\r\n3980\r\n[18] (pry) main: 0> Manager.where(dominant_product_type: \"liquidity_fund\").count\r\n   (8.4ms)  SELECT COUNT(*) FROM \"managers\"  WHERE \"managers\".\"dominant_product_type\" = 0\r\n3980\r\n[20] (pry) main: 0> Manager.where(dominant_product_type: Manager.dominant_product_types[\"liquidity_fund\"]).count\r\n   (7.5ms)  SELECT COUNT(*) FROM \"managers\"  WHERE \"managers\".\"dominant_product_type\" = 1\r\n22\r\n```\r\nNotice, zero is used in the first two queries. The third query is correct.\r\n\r\nA related issue is this, using the example from the docs:\r\n\r\nShould this code give the same result or different:\r\n\r\n```ruby\r\nstatuses = Conversation.select(:status).where.not(status: nil).distinct.map(&:status)\r\n```\r\n\r\nas compared to:\r\n\r\n```ruby\r\nstatuses = Conversation.distinct.where.not(status: nil).pluck(:status)\r\n```\r\n\r\nIn the first case, you get back an Array with 2 strings: =[\"active\",\r\n\"archived\"]=. In the second case, you get back an Array with 2 integers: [0, 1].\r\n\r\nIf the core team deems this worthy, I could try my hand at a PR to implement this. \r\n\r\nAt the minimum, this seems worthy for the documentation.\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/74898236","html_url":"https://github.com/rails/rails/issues/17226#issuecomment-74898236","issue_url":"https://api.github.com/repos/rails/rails/issues/17226","id":74898236,"user":{"login":"fabn","id":324213,"avatar_url":"https://avatars.githubusercontent.com/u/324213?v=3","gravatar_id":"","url":"https://api.github.com/users/fabn","html_url":"https://github.com/fabn","followers_url":"https://api.github.com/users/fabn/followers","following_url":"https://api.github.com/users/fabn/following{/other_user}","gists_url":"https://api.github.com/users/fabn/gists{/gist_id}","starred_url":"https://api.github.com/users/fabn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabn/subscriptions","organizations_url":"https://api.github.com/users/fabn/orgs","repos_url":"https://api.github.com/users/fabn/repos","events_url":"https://api.github.com/users/fabn/events{/privacy}","received_events_url":"https://api.github.com/users/fabn/received_events","type":"User","site_admin":false},"created_at":"2015-02-18T16:43:57Z","updated_at":"2015-02-18T16:43:57Z","body":"I saw that this has been implemented in master with this commit https://github.com/rails/rails/commit/c51f9b61ce1e167f5f58f07441adcfa117694301\r\n\r\nHowever the commit is only in master branch, will that commit backported in 4.2.x or it's just for rails 5.x?"}}