Permalink
Browse files

Close #5990

  • Loading branch information...
1 parent 7d5146e commit bdedc7a2e42d43784c8502c3abeab5905e1906d2 twinturbo committed Apr 30, 2012
@@ -125,6 +125,12 @@ def pluck(column_name)
column_name = "#{table_name}.#{column_name}"
end
+ if eager_loading? || (includes_values.present? && references_eager_loaded_tables?)
+ return construct_relation_for_association_calculations.pluck(column_name)
+ else
+ result = @klass.connection.select_all(select(column_name).arel, nil, bind_values)
+ end
+
result = klass.connection.select_all(select(column_name).arel, nil, bind_values)
types = result.column_types.merge klass.column_types
column = types[key]
@@ -465,4 +465,9 @@ def test_pluck_not_auto_table_name_prefix_if_column_joined
Company.create!(:name => "test", :contracts => [Contract.new(:developer_id => 7)])
assert_equal [7], Company.joins(:contracts).pluck(:developer_id)
end
+
+ def test_pluck_if_table_included
+ c = Company.create!(:name => "test", :contracts => [Contract.new(:developer_id => 7)])
+ assert_equal [c.id], Company.includes(:contracts).where("contracts.id" => c.contracts.first).pluck(:id)
+ end
end

0 comments on commit bdedc7a

Please sign in to comment.