Created
August 6, 2013 04:46
-
-
Save benhamill/6162089 to your computer and use it in GitHub Desktop.
includes + where + select Ignores Your select_values See [this repo](https://github.com/benhamill/ar_include_test#whats-up-with-includes) for an interactive explanation, which might aid investigation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'activerecord', '4.0.0' | |
require 'active_record' | |
require 'sqlite3' | |
require 'logger' | |
require 'minitest/autorun' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :users do |t| | |
t.string :name | |
end | |
create_table :comments do |t| | |
t.string :body | |
t.integer :user_id | |
end | |
end | |
class User < ActiveRecord::Base | |
has_many :comments | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :user | |
end | |
class BugTest < MiniTest::Unit::TestCase | |
def test_includes_where_select | |
query = User.select('random() AS ranking').order('ranking').includes(:comments) | |
.where(comments: { id: 1 }) | |
assert_equal ['random() AS ranking'], query.select_values | |
assert_equal [], query.to_a | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment