diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-05-07 13:12:46 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-05-07 13:12:46 +0200 |
commit | c2c84ece354ea359293bf74978c525178404fb6f (patch) | |
tree | 33f150d829b4b53c6beb126a7198f842d0c89a42 /activerecord/lib | |
parent | cbc554be3d22bb25c95fdbbaadda20c22947b42b (diff) | |
parent | 22f251832ccd227c6dc34ae6c55ebe02547d05d6 (diff) | |
download | rails-c2c84ece354ea359293bf74978c525178404fb6f.tar.gz rails-c2c84ece354ea359293bf74978c525178404fb6f.tar.bz2 rails-c2c84ece354ea359293bf74978c525178404fb6f.zip |
Merge pull request #14993 from jonatack/patch-7
Follow-up to #14990 [ci skip]
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index cdabf02b95..0b122d2070 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -12,10 +12,11 @@ module ActiveRecord @through_association = nil end - # Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been - # loaded and calling collection.size if it has. If it's more likely than not that the collection does - # have a size larger than zero, and you need to fetch that collection afterwards, it'll take one fewer - # SELECT query if you use #length. + # Returns the size of the collection by executing a SELECT COUNT(*) query + # if the collection hasn't been loaded, and by calling collection.size if + # it has. If the collection will likely have a size greater than zero, + # and if fetching the collection will be needed afterwards, one less + # SELECT query will be generated by using #length instead. def size if has_cached_counter? owner.read_attribute cached_counter_attribute_name(reflection) @@ -72,13 +73,11 @@ module ActiveRecord @through_association ||= owner.association(through_reflection.name) end - # We temporarily cache through record that has been built, because if we build a - # through record in build_record and then subsequently call insert_record, then we - # want to use the exact same object. + # The through record (built with build_record) is temporarily cached + # so that it may be reused if insert_record is subsequently called. # - # However, after insert_record has been called, we clear the cache entry because - # we want it to be possible to have multiple instances of the same record in an - # association + # However, after insert_record has been called, the cache is cleared in + # order to allow multiple instances of the same record in an association. def build_through_record(record) @through_records[record.object_id] ||= begin ensure_mutable |