Class: ActiveRecord::Associations::HasManyThroughAssociation
- Inherits:
-
HasManyAssociation
- Object
- AssociationProxy
- AssociationCollection
- HasManyAssociation
- ActiveRecord::Associations::HasManyThroughAssociation
- Includes:
- ThroughAssociation
- Defined in:
- activerecord/lib/active_record/associations/has_many_through_association.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from AssociationProxy
Instance Method Summary (collapse)
- - (Object) destroy(*records)
-
- (Object) size
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.
Methods inherited from AssociationCollection
#<<, #any?, #build, #clear, #count, #create, #create!, #delete, #delete_all, #destroy_all, #empty?, #find, #first, #include?, #last, #length, #many?, #method_missing, #replace, #reset, #respond_to?, #select, #sum, #to_ary, #transaction, #uniq
Methods inherited from AssociationProxy
#===, #aliased_table_name, #initialize, #inspect, #loaded!, #loaded?, #method_missing, #proxy_owner, #proxy_reflection, #reload, #reset, #respond_to?, #scoped, #send, #stale_target?, #to_param
Constructor Details
This class inherits a constructor from ActiveRecord::Associations::AssociationProxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveRecord::Associations::AssociationCollection
Instance Method Details
- (Object) destroy(*records)
11 12 13 14 15 16 |
# File 'activerecord/lib/active_record/associations/has_many_through_association.rb', line 11 def destroy(*records) transaction do delete_records(records.flatten) super end end |
- (Object) size
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.
22 23 24 25 26 27 28 29 30 |
# File 'activerecord/lib/active_record/associations/has_many_through_association.rb', line 22 def size if has_cached_counter? @owner.send(:read_attribute, cached_counter_attribute_name) elsif loaded? @target.size else count end end |