class ActiveRecord::Associations::HasCount

Public Instance Methods

load_target() click to toggle source

Not preloaded behaviour of has_count association When this method is called, it will be N+1 query

# File lib/active_record/associations/has_count.rb, line 6
def load_target
  count_target = reflection.name_without_count.to_sym
  @target = owner.association(count_target).count

  loaded! unless loaded?
  target
rescue ActiveRecord::RecordNotFound
  reset
end