{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/12423","labels_url":"https://api.github.com/repos/rails/rails/issues/12423/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/12423/comments","events_url":"https://api.github.com/repos/rails/rails/issues/12423/events","html_url":"https://github.com/rails/rails/issues/12423","id":20379349,"number":12423,"title":"Additional select columns are removed when using `inludes`","user":{"login":"dnagir","id":195035,"avatar_url":"https://avatars.githubusercontent.com/u/195035?v=3","gravatar_id":"","url":"https://api.github.com/users/dnagir","html_url":"https://github.com/dnagir","followers_url":"https://api.github.com/users/dnagir/followers","following_url":"https://api.github.com/users/dnagir/following{/other_user}","gists_url":"https://api.github.com/users/dnagir/gists{/gist_id}","starred_url":"https://api.github.com/users/dnagir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnagir/subscriptions","organizations_url":"https://api.github.com/users/dnagir/orgs","repos_url":"https://api.github.com/users/dnagir/repos","events_url":"https://api.github.com/users/dnagir/events{/privacy}","received_events_url":"https://api.github.com/users/dnagir/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/activerecord","name":"activerecord","color":"0b02e1"},{"url":"https://api.github.com/repos/rails/rails/labels/attached%20PR","name":"attached PR","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2013-10-02T07:57:30Z","updated_at":"2015-07-27T08:37:03Z","closed_at":null,"body":"Repro:\r\n\r\n```ruby\r\ngem 'activerecord', '4.0.0'\r\nrequire 'active_record'\r\nrequire 'minitest/autorun'\r\nrequire 'logger'\r\n\r\nActiveRecord::Base.logger = Logger.new(STDOUT)\r\nActiveRecord::Base.establish_connection(\r\n  :adapter  => 'postgresql',\r\n  :database => 'x'\r\n)\r\n\r\nActiveRecord::Schema.define do\r\n  create_table :blogs, :force => true do |t|\r\n  end\r\n\r\n  create_table :posts, :force => true do |t|\r\n    t.integer :blog_id\r\n  end\r\nend\r\n\r\nclass Blog < ActiveRecord::Base\r\n  has_many :posts, :dependent => :destroy\r\nend\r\n\r\nclass Post < ActiveRecord::Base\r\n  belongs_to :blog\r\nend\r\n\r\nclass TestMe < MiniTest::Unit::TestCase\r\n  def test_includes_with_additional_column\r\n    blog = Blog.create!\r\n    blogs = Blog.select(Blog.column_names + [\"'foo' as foo\"]).references(:posts).includes(:posts).order('foo').to_a\r\n    assert_equal [blog], blogs\r\n    assert_equal 'foo', blogs.first.foo\r\n  end\r\nend\r\n```\r\n\r\nTest fails with:\r\n\r\n```\r\n-- create_table(:blogs, {:force=>true})\r\nD, [2013-10-02T17:55:54.494325 #57438] DEBUG -- :    (1.6ms)  DROP TABLE \"blogs\"\r\nD, [2013-10-02T17:55:54.496579 #57438] DEBUG -- :    (2.1ms)  CREATE TABLE \"blogs\" (\"id\" serial primary key) \r\n   -> 0.0163s\r\n-- create_table(:posts, {:force=>true})\r\nD, [2013-10-02T17:55:54.498144 #57438] DEBUG -- :    (0.7ms)  DROP TABLE \"posts\"\r\nD, [2013-10-02T17:55:54.499617 #57438] DEBUG -- :    (1.3ms)  CREATE TABLE \"posts\" (\"id\" serial primary key, \"blog_id\" integer) \r\n   -> 0.0030s\r\nMiniTest::Unit::TestCase is now Minitest::Test. From tmp/test.rb:29:in `<main>'\r\nRun options: --seed 30747\r\n\r\n# Running:\r\n\r\nD, [2013-10-02T17:55:54.531233 #57438] DEBUG -- :    (0.1ms)  BEGIN\r\nD, [2013-10-02T17:55:54.536553 #57438] DEBUG -- :   SQL (0.5ms)  INSERT INTO \"blogs\" DEFAULT VALUES RETURNING \"id\"\r\nD, [2013-10-02T17:55:54.536987 #57438] DEBUG -- :    (0.1ms)  COMMIT\r\nD, [2013-10-02T17:55:54.545380 #57438] DEBUG -- :   SQL (0.4ms)  SELECT \"blogs\".\"id\" AS t0_r0, \"posts\".\"id\" AS t1_r0, \"posts\".\"blog_id\" AS t1_r1 FROM \"blogs\" LEFT OUTER JOIN \"posts\" ON \"posts\".\"blog_id\" = \"blogs\".\"id\" ORDER BY foo\r\nE, [2013-10-02T17:55:54.545437 #57438] ERROR -- : PG::UndefinedColumn: ERROR:  column \"foo\" does not exist\r\nLINE 1: ...IN \"posts\" ON \"posts\".\"blog_id\" = \"blogs\".\"id\"  ORDER BY foo\r\n                                                                    ^\r\n: SELECT \"blogs\".\"id\" AS t0_r0, \"posts\".\"id\" AS t1_r0, \"posts\".\"blog_id\" AS t1_r1 FROM \"blogs\" LEFT OUTER JOIN \"posts\" ON \"posts\".\"blog_id\" = \"blogs\".\"id\"  ORDER BY foo\r\nE\r\n\r\nFinished in 0.018798s, 53.1971 runs/s, 0.0000 assertions/s.\r\n\r\n  1) Error:\r\nTestMe#test_includes_with_additional_column:\r\nActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column \"foo\" does not exist\r\nLINE 1: ...IN \"posts\" ON \"posts\".\"blog_id\" = \"blogs\".\"id\"  ORDER BY foo\r\n                                                                    ^\r\n: SELECT \"blogs\".\"id\" AS t0_r0, \"posts\".\"id\" AS t1_r0, \"posts\".\"blog_id\" AS t1_r1 FROM \"blogs\" LEFT OUTER JOIN \"posts\" ON \"posts\".\"blog_id\" = \"blogs\".\"id\"  ORDER BY foo\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_no_cache'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `block in exec_query'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:885:in `select'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:24:in `select_all'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/relation/finder_methods.rb:206:in `find_with_associations'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/relation.rb:585:in `exec_queries'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/relation.rb:471:in `load'\r\n    /Users/dnagir/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/relation.rb:220:in `to_a'\r\n    tmp/test.rb:32:in `test_includes_with_additional_column'\r\n\r\n1 runs, 0 assertions, 0 failures, 1 errors, 0 skips\r\n```"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/125127406","html_url":"https://github.com/rails/rails/issues/12423#issuecomment-125127406","issue_url":"https://api.github.com/repos/rails/rails/issues/12423","id":125127406,"user":{"login":"vmeyet","id":2462303,"avatar_url":"https://avatars.githubusercontent.com/u/2462303?v=3","gravatar_id":"","url":"https://api.github.com/users/vmeyet","html_url":"https://github.com/vmeyet","followers_url":"https://api.github.com/users/vmeyet/followers","following_url":"https://api.github.com/users/vmeyet/following{/other_user}","gists_url":"https://api.github.com/users/vmeyet/gists{/gist_id}","starred_url":"https://api.github.com/users/vmeyet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmeyet/subscriptions","organizations_url":"https://api.github.com/users/vmeyet/orgs","repos_url":"https://api.github.com/users/vmeyet/repos","events_url":"https://api.github.com/users/vmeyet/events{/privacy}","received_events_url":"https://api.github.com/users/vmeyet/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T08:37:03Z","updated_at":"2015-07-27T08:37:03Z","body":"still not working in Rails `4.2.3`. Ping for updates?\r\n\r\nThat's kind of an annoying bug :cry:"}}