aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorpavel <pavel.rosicky@easy.cz>2017-10-26 23:16:54 +0200
committerpavel <pavel.rosicky@easy.cz>2017-10-27 01:09:11 +0200
commitd95fbd7dba54cfbd282f808102dfdffa3499d669 (patch)
treefe4a5a7c6253321e2da64d60c22a0bb673a7f1e8 /activerecord
parent12de5e202ddfca27cccc5965b3048e88718a9ace (diff)
downloadrails-d95fbd7dba54cfbd282f808102dfdffa3499d669.tar.gz
rails-d95fbd7dba54cfbd282f808102dfdffa3499d669.tar.bz2
rails-d95fbd7dba54cfbd282f808102dfdffa3499d669.zip
fix initial count
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/alias_tracker.rb2
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/alias_tracker.rb b/activerecord/lib/active_record/associations/alias_tracker.rb
index 07bd0a273b..14881cfe17 100644
--- a/activerecord/lib/active_record/associations/alias_tracker.rb
+++ b/activerecord/lib/active_record/associations/alias_tracker.rb
@@ -33,7 +33,7 @@ module ActiveRecord
elsif join.respond_to? :left
join.left.name == name ? 1 : 0
elsif join.is_a?(Hash)
- join[name]
+ join.fetch(name, 0)
else
# this branch is reached by two tests:
#
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index c6a4ac356f..1dbc407fd1 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -1258,6 +1258,10 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal [comments(:eager_other_comment1)], authors(:mary).unordered_comments
end
+ def test_has_many_trough_with_scope_should_accept_string_and_hash_join
+ assert_equal authors(:david), Author.joins({ comments_for_first_author: :post }, "inner join posts posts_alias on authors.id = posts_alias.author_id").eager_load(:categories).take
+ end
+
def test_has_many_through_with_scope_should_respect_table_alias
family = Family.create!
users = 3.times.map { User.create! }