Permalink
Browse files

Close #5990 Against 3.2 stable

  • Loading branch information...
1 parent 0df261a commit b882a61a744d0ab1be1b2cb1fb27183267b2c8ce twinturbo committed Apr 30, 2012
@@ -177,9 +177,17 @@ def calculate(operation, column_name, options = {})
# Person.where(:confirmed => true).limit(5).pluck(:id)
#
def pluck(column_name)
- column_name = column_name.to_s
- klass.connection.select_all(select(column_name).arel).map! do |attributes|
- klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes))
+
+ if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s)
+ 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
+ klass.connection.select_all(select(column_name).arel).map! do |attributes|
+ klass.type_cast_attribute(attributes.keys.first, klass.initialize_attributes(attributes))
+ end
end
end
@@ -478,4 +478,9 @@ def test_pluck_with_serialization
def test_pluck_with_qualified_column_name
assert_equal [1,2,3,4], Topic.order(:id).pluck("topics.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

1 comment on commit b882a61

parndt commented on b882a61 Nov 25, 2012

Doesn't appear like this was this ever merged to rails/rails?

Please sign in to comment.