diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-09-11 05:46:12 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-10-29 17:53:33 +0900 |
commit | b6ddaa4266c7d77fca9a61037c4455cfbf9d77a9 (patch) | |
tree | 76d5f7cbb2025827eafc5552ec6d9581f7cf299b /activerecord/lib/active_record/associations | |
parent | fe1f4b2ad56f010a4e9b93d547d63a15953d9dc2 (diff) | |
download | rails-b6ddaa4266c7d77fca9a61037c4455cfbf9d77a9.tar.gz rails-b6ddaa4266c7d77fca9a61037c4455cfbf9d77a9.tar.bz2 rails-b6ddaa4266c7d77fca9a61037c4455cfbf9d77a9.zip |
Remove unnecessary `target.uniq.size` in `CollectionAssociation#size`
If `association_scope` have `distinct_value`, same record cannot exist
in `target`.
https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/associations/collection_association.rb#L419-L424
```ruby
def add_to_target(record, skip_callbacks = false, &block)
if association_scope.distinct_value
index = @target.index(record)
end
replace_on_target(record, index, skip_callbacks, &block)
end
```
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 278c95e27b..a253c3a67a 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -222,11 +222,7 @@ module ActiveRecord # +count_records+, which is a method descendants have to provide. def size if !find_target? || loaded? - if association_scope.distinct_value - target.uniq.size - else - target.size - end + target.size elsif !association_scope.group_values.empty? load_target.size elsif !association_scope.distinct_value && target.is_a?(Array) |