Permalink
Browse files

Merge pull request #14993 from jonatack/patch-7

Follow-up to #14990 [ci skip]
  • Loading branch information...
2 parents cbc554b + 22f2518 commit c2c84ece354ea359293bf74978c525178404fb6f @senny senny committed May 7, 2014
Showing with 9 additions and 10 deletions.
  1. +9 −10 activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -12,10 +12,11 @@ def initialize(owner, reflection)
@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 @@ def through_association
@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

0 comments on commit c2c84ec

Please sign in to comment.