{"action":"closed","issue":{"url":"https://api.github.com/repos/rails/rails/issues/18280","labels_url":"https://api.github.com/repos/rails/rails/issues/18280/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/18280/comments","events_url":"https://api.github.com/repos/rails/rails/issues/18280/events","html_url":"https://github.com/rails/rails/issues/18280","id":53212692,"number":18280,"title":"4.2.0: undefined method `val' for Arel::Nodes::SelectStatement","user":{"login":"jaredbeck","id":380809,"avatar_url":"https://avatars.githubusercontent.com/u/380809?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredbeck","html_url":"https://github.com/jaredbeck","followers_url":"https://api.github.com/users/jaredbeck/followers","following_url":"https://api.github.com/users/jaredbeck/following{/other_user}","gists_url":"https://api.github.com/users/jaredbeck/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredbeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredbeck/subscriptions","organizations_url":"https://api.github.com/users/jaredbeck/orgs","repos_url":"https://api.github.com/users/jaredbeck/repos","events_url":"https://api.github.com/users/jaredbeck/events{/privacy}","received_events_url":"https://api.github.com/users/jaredbeck/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-01T04:19:58Z","updated_at":"2015-01-01T14:10:18Z","closed_at":"2015-01-01T14:10:18Z","body":"In a new rails 4.2.0 app (https://github.com/jaredbeck/rails42_arel_val_error) there are three models, whose names have been changed to protect the innocent.\r\n\r\nBanana belongs_to Bowl, which belongs_to Kitchen.  Banana has a (unusual) default scope that references a (unusual) scope in Bowl.  When we call Banana.new, we get \r\n\r\n    NoMethodError: undefined method `val' for #<Arel::Nodes::SelectStatement:0x007fbceb437380>\r\n\r\nIn the app, see `spec/models/banana_spec.rb` for a spec that reproduces this error.\r\n\r\nDigging a bit, I found that after [this change](https://github.com/rails/rails/commit/426ae869fe85462f5592fb225b431144804e25af) to AR, the `where_values_hash` method seems to no longer support sub-queries.\r\n\r\nFor example, if we use a debugger to inspect `where` and `where.right` ..\r\n\r\n```\r\n[1] pry(#<Banana::ActiveRecord_Relation>)> where.to_sql\r\n=> \"bananas\".\"bowl_id\" IN (\r\n  SELECT \"bowls\".\"id\" \r\n  FROM \"bowls\" \r\n  INNER JOIN \"kitchens\" ON \"kitchens\".\"id\" = \"bowls\".\"kitchen_id\" \r\n  WHERE \"bowls\".\"active\" = 't' AND \"kitchens\".\"active\" = 't'\r\n)\r\n[2] pry(#<Banana::ActiveRecord_Relation>)> where.right.to_sql\r\n=> SELECT \"bowls\".\"id\" \r\n  FROM \"bowls\" \r\n  INNER JOIN \"kitchens\" ON \"kitchens\".\"id\" = \"bowls\".\"kitchen_id\" \r\n  WHERE \"bowls\".\"active\" = 't' AND \"kitchens\".\"active\" = 't'\r\n```\r\n\r\n.. we see that `where.right` is a `SELECT`.\r\n\r\nIf there is a better way to implement this, I'd welcome it.  It's not my code, I'm just trying to upgrade it to rails 4.2.  But, just in case you think it's a bug in AR or arel, I thought you'd appreciate an executable bug report."}}