aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-11-09 11:40:33 +0000
committerJon Leighton <j@jonathanleighton.com>2012-11-09 11:43:15 +0000
commit11b846eefb1e7128ae9c63035f6d559d50bd4563 (patch)
tree85deeca9c52c391d777bbbec570e5290eda5d6fc /activerecord
parentaae4f357b5dae389b91129258f9d6d3043e7631e (diff)
downloadrails-11b846eefb1e7128ae9c63035f6d559d50bd4563.tar.gz
rails-11b846eefb1e7128ae9c63035f6d559d50bd4563.tar.bz2
rails-11b846eefb1e7128ae9c63035f6d559d50bd4563.zip
CollectionProxy#pluck issues no query for a new_record? owner
Fixes #8102. I couldn't find a nicer way to deal with this than delegate the call to #scope, which will be a NullRelation when we want it to be.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb4
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb1
2 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 50f9fca7c0..e044099b72 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -965,6 +965,10 @@ module ActiveRecord
proxy_association.reload
self
end
+
+ def pluck(column_names)
+ scope.pluck(column_names)
+ end
end
end
end
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 6355094a79..baf07f352e 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1655,6 +1655,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_no_queries do
assert_equal [], post.comments
assert_equal [], post.comments.where(body: 'omg')
+ assert_equal [], post.comments.pluck(:body)
end
end
end