Skip to content
Browse files

Merge pull request #9782 from vipulnsward/change_from_each_to_each_ke…

…y_habtm

Change from each to each_value;drop assignment in habtm
  • Loading branch information...
2 parents c24528f + aee5424 commit 8621b699177263592e2b127ba9625fed0b404587 @rafaelfranca rafaelfranca committed Mar 18, 2013
View
2 activerecord/lib/active_record/associations/preloader/has_and_belongs_to_many.rb
@@ -35,7 +35,7 @@ def association_key
# record
def associated_records_by_owner
records = {}
- super.each do |owner_key, rows|
+ super.each_value do |rows|
rows.map! { |row| records[row[klass.primary_key]] ||= klass.instantiate(row) }
end
end
View
4 activerecord/test/cases/associations/eager_test.rb
@@ -467,7 +467,7 @@ def test_eager_with_has_many_through
posts_with_comments = people(:michael).posts.merge(:includes => :comments, :order => 'posts.id').to_a
posts_with_author = people(:michael).posts.merge(:includes => :author, :order => 'posts.id').to_a
posts_with_comments_and_author = people(:michael).posts.merge(:includes => [ :comments, :author ], :order => 'posts.id').to_a
- assert_equal 2, posts_with_comments.inject(0) { |sum, post| sum += post.comments.size }
+ assert_equal 2, posts_with_comments.inject(0) { |sum, post| sum + post.comments.size }
assert_equal authors(:david), assert_no_queries { posts_with_author.first.author }
assert_equal authors(:david), assert_no_queries { posts_with_comments_and_author.first.author }
end
@@ -523,7 +523,7 @@ def test_eager_with_has_many_through_join_model_ignores_default_includes
def test_eager_with_has_many_and_limit
posts = Post.all.merge!(:order => 'posts.id asc', :includes => [ :author, :comments ], :limit => 2).to_a
assert_equal 2, posts.size
- assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size }
+ assert_equal 3, posts.inject(0) { |sum, post| sum + post.comments.size }
end
def test_eager_with_has_many_and_limit_and_conditions

0 comments on commit 8621b69

Please sign in to comment.
Something went wrong with that request. Please try again.