Class: ActiveRecord::Associations::HasManyThroughAssociation

Inherits:
HasManyAssociation show all
Includes:
ThroughAssociationScope
Defined in:
lib/active_record/associations/has_many_through_association.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from HasManyAssociation

#initialize

Methods inherited from AssociationCollection

#<<, #any?, #build, #clear, #count, #delete, #delete_all, #destroy_all, #empty?, #find, #first, #include?, #initialize, #last, #length, #many?, #proxy_respond_to?, #replace, #reset, #scoped, #select, #sum, #to_ary, #transaction, #uniq

Methods inherited from AssociationProxy

#===, #aliased_table_name, #conditions, #initialize, #inspect, #loaded, #loaded?, #proxy_owner, #proxy_reflection, #proxy_respond_to?, #proxy_target, #reload, #reset, #respond_to?, #send, #target, #target=

Constructor Details

This class inherits a constructor from ActiveRecord::Associations::HasManyAssociation

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveRecord::Associations::AssociationCollection

Instance Method Details

#create(attrs = nil) ⇒ Object



16
17
18
# File 'lib/active_record/associations/has_many_through_association.rb', line 16

def create(attrs = nil)
  create_record(attrs, false)
end

#create!(attrs = nil) ⇒ Object



12
13
14
# File 'lib/active_record/associations/has_many_through_association.rb', line 12

def create!(attrs = nil)
  create_record(attrs, true)
end

#destroy(*records) ⇒ Object



20
21
22
23
24
25
# File 'lib/active_record/associations/has_many_through_association.rb', line 20

def destroy(*records)
  transaction do
    delete_records(flatten_deeper(records))
    super
  end
end

#sizeObject

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.



31
32
33
34
35
# File 'lib/active_record/associations/has_many_through_association.rb', line 31

def size
  return @owner.send(:read_attribute, cached_counter_attribute_name) if has_cached_counter?
  return @target.size if loaded?
  return count
end