Class: ActiveRecord::Associations::HasManyThroughAssociation
- Inherits:
-
AssociationProxy
- Object
- AssociationProxy
- ActiveRecord::Associations::HasManyThroughAssociation
- Defined in:
- lib/active_record/associations/has_many_through_association.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from AssociationProxy
Instance Method Summary collapse
- #find(*args) ⇒ Object
-
#initialize(owner, reflection) ⇒ HasManyThroughAssociation
constructor
A new instance of HasManyThroughAssociation.
- #reset ⇒ Object
Methods inherited from AssociationProxy
#===, #aliased_table_name, #loaded, #loaded?, #proxy_respond_to?, #reload, #respond_to?, #target, #target=
Constructor Details
#initialize(owner, reflection) ⇒ HasManyThroughAssociation
Returns a new instance of HasManyThroughAssociation.
4 5 6 7 8 9 |
# File 'lib/active_record/associations/has_many_through_association.rb', line 4 def initialize(owner, reflection) super reflection.check_validity! @finder_sql = construct_conditions construct_sql end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
45 46 47 48 49 50 51 |
# File 'lib/active_record/associations/has_many_through_association.rb', line 45 def method_missing(method, *args, &block) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) super else @reflection.klass.with_scope(construct_scope) { @reflection.klass.send(method, *args, &block) } end end |
Instance Method Details
#find(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record/associations/has_many_through_association.rb', line 12 def find(*args) = Base.send(:extract_options_from_args!, args) conditions = "#{@finder_sql}" if sanitized_conditions = sanitize_sql([:conditions]) conditions << " AND (#{sanitized_conditions})" end [:conditions] = conditions if [:order] && @reflection.[:order] [:order] = "#{[:order]}, #{@reflection.[:order]}" elsif @reflection.[:order] [:order] = @reflection.[:order] end [:select] = construct_select([:select]) [:from] ||= construct_from [:joins] = construct_joins([:joins]) [:include] = @reflection.source_reflection.[:include] if [:include].nil? () # Pass through args exactly as we received them. args << @reflection.klass.find(*args) end |
#reset ⇒ Object
39 40 41 42 |
# File 'lib/active_record/associations/has_many_through_association.rb', line 39 def reset @target = [] @loaded = false end |