aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relations_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2019-03-29 16:01:45 -0700
committerGitHub <noreply@github.com>2019-03-29 16:01:45 -0700
commit4e076b03b6312b928a845f9a31288d10d7243338 (patch)
tree0c3a4a9316ee19626dcdaabec7c33e355ba03c56 /activerecord/test/cases/relations_test.rb
parent406d3a926cfcd3724f8002f70346aad95eed4a8c (diff)
downloadrails-4e076b03b6312b928a845f9a31288d10d7243338.tar.gz
rails-4e076b03b6312b928a845f9a31288d10d7243338.tar.bz2
rails-4e076b03b6312b928a845f9a31288d10d7243338.zip
Add `ActiveRecord::Relation#extract_associated` for extracting associated record (#35784)
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r--activerecord/test/cases/relations_test.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 36b4000018..131e034c66 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -602,6 +602,13 @@ class RelationTest < ActiveRecord::TestCase
end
end
+ def test_extracted_association
+ relation_authors = assert_queries(2) { Post.all.extract_associated(:author) }
+ root_authors = assert_queries(2) { Post.extract_associated(:author) }
+ assert_equal relation_authors, root_authors
+ assert_equal Post.all.collect(&:author), relation_authors
+ end
+
def test_find_with_included_associations
assert_queries(2) do
posts = Post.includes(:comments).order("posts.id")