diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2019-02-01 15:58:09 +0200 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2019-02-05 11:58:59 +0200 |
commit | f1b64dff47fcd0f05bbba1ec88e37a62b9f0b48f (patch) | |
tree | 6df5f0d885deab4ea7e608ddd3a65a1dedb30433 /activerecord/lib/active_record/associations/collection_association.rb | |
parent | 4ae8d6182fd9351b9451003f9380d8855f3f5a94 (diff) | |
download | rails-f1b64dff47fcd0f05bbba1ec88e37a62b9f0b48f.tar.gz rails-f1b64dff47fcd0f05bbba1ec88e37a62b9f0b48f.tar.bz2 rails-f1b64dff47fcd0f05bbba1ec88e37a62b9f0b48f.zip |
Bugfix association loading behavior when counter cache is zero
Diffstat (limited to 'activerecord/lib/active_record/associations/collection_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 4a25567c9d..6f5df807fe 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -210,7 +210,8 @@ module ActiveRecord # This method is abstract in the sense that it relies on # +count_records+, which is a method descendants have to provide. def size - if !find_target? || loaded? + if !find_target? + loaded! unless loaded? target.size elsif @association_ids @association_ids.size @@ -233,7 +234,7 @@ module ActiveRecord # loaded and you are going to fetch the records anyway it is better to # check <tt>collection.length.zero?</tt>. def empty? - if loaded? || @association_ids + if loaded? || @association_ids || reflection.has_cached_counter? size.zero? else target.empty? && !scope.exists? |