{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/20611","labels_url":"https://api.github.com/repos/rails/rails/issues/20611/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/20611/comments","events_url":"https://api.github.com/repos/rails/rails/issues/20611/events","html_url":"https://github.com/rails/rails/issues/20611","id":89129021,"number":20611,"title":"ActiveRecord Associations PG incorrectly handles uuid ID","user":{"login":"avongluck-r1soft","id":12514863,"avatar_url":"https://avatars.githubusercontent.com/u/12514863?v=3","gravatar_id":"","url":"https://api.github.com/users/avongluck-r1soft","html_url":"https://github.com/avongluck-r1soft","followers_url":"https://api.github.com/users/avongluck-r1soft/followers","following_url":"https://api.github.com/users/avongluck-r1soft/following{/other_user}","gists_url":"https://api.github.com/users/avongluck-r1soft/gists{/gist_id}","starred_url":"https://api.github.com/users/avongluck-r1soft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avongluck-r1soft/subscriptions","organizations_url":"https://api.github.com/users/avongluck-r1soft/orgs","repos_url":"https://api.github.com/users/avongluck-r1soft/repos","events_url":"https://api.github.com/users/avongluck-r1soft/events{/privacy}","received_events_url":"https://api.github.com/users/avongluck-r1soft/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-06-17T21:22:25Z","updated_at":"2015-06-17T22:32:40Z","closed_at":null,"body":"ActiveRecord Assocations with PG incorrectly handles uuid key id types.\r\n\r\n*    rails (4.2.1)\r\n   *   actionmailer (= 4.2.1)\r\n   *   actionpack (= 4.2.1)\r\n   *   actionview (= 4.2.1)\r\n   *   activejob (= 4.2.1)\r\n   *   activemodel (= 4.2.1)\r\n   *   activerecord (= 4.2.1)\r\n   *   activesupport (= 4.2.1)\r\n   *   bundler (>= 1.3.0, < 2.0)\r\n   *   railties (= 4.2.1)\r\n   *   sprockets-rails\r\n\r\n\r\n**Example:**\r\n  enable_extension \"uuid-ossp\"\r\n\r\n**Schema:**\r\nsbm \r\n```\r\ndef change\r\n    remove_column :sbms, :id\r\n    rename_column :sbms, :uuid, :id\r\n    execute \"ALTER TABLE sbms ADD PRIMARY KEY (id);\"\r\nend\r\n```\r\nsbm_stats\r\n```    t.uuid     \"sbm_id\"```\r\n\r\n**Relations:**\r\nclass SbmStat < ActiveRecord::Base\r\n    belongs_to :sbm\r\nend\r\nclass Sbm < ActiveRecord::Base\r\n    has_many :sbm_stats\r\nend\r\n\r\n**Forms incorrect SQL**\r\n```@sbm.sbm_stats.where(:name => \"cpu_user\")```\r\n\r\n(notice the WHERE \"sbm_stats\".\"sbm_id\" = $1 below)\r\n```PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: \"da4340f6-89a2-4039-90ec-5781d84c155e\" : SELECT \"sbm_stats\".* FROM \"sbm_stats\" WHERE \"sbm_stats\".\"sbm_id\" = $1 AND \"sbm_stats\".\"name\" = $2 ORDER BY \"sbm_stats\".\"time\" DESC```\r\n\r\n**Forms correct SQL (bypassing ActiveRecord Associations)**\r\n```SbmStat.where(:name => \"cpu_user\", :sbm_id => @sbm.id)```\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/112970722","html_url":"https://github.com/rails/rails/issues/20611#issuecomment-112970722","issue_url":"https://api.github.com/repos/rails/rails/issues/20611","id":112970722,"user":{"login":"matthewd","id":1034,"avatar_url":"https://avatars.githubusercontent.com/u/1034?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewd","html_url":"https://github.com/matthewd","followers_url":"https://api.github.com/users/matthewd/followers","following_url":"https://api.github.com/users/matthewd/following{/other_user}","gists_url":"https://api.github.com/users/matthewd/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewd/subscriptions","organizations_url":"https://api.github.com/users/matthewd/orgs","repos_url":"https://api.github.com/users/matthewd/repos","events_url":"https://api.github.com/users/matthewd/events{/privacy}","received_events_url":"https://api.github.com/users/matthewd/received_events","type":"User","site_admin":false},"created_at":"2015-06-17T22:32:40Z","updated_at":"2015-06-17T22:32:40Z","body":"A hopefully-obvious question, just for my own sanity: these are both from the same machine, talking to the same database instance, where the only thing that's changed between them is that line of code, right?\r\n\r\nBecause the second one really sounds like PostgreSQL thinks `\"sbm_stats\".\"sbm_id\"` is an integer.\r\n\r\nWas that recently the case?"}}