Class: Babik::Association::SelectRelatedAssociationChain

Inherits:
ForeignAssociationChain show all
Defined in:
lib/babik/queryset/lib/association/select_related_association_chain.rb

Overview

Association chain for association paths An association chain is a chain of associations where the target model of association i is the origin model of association i + 1 Remember, an association path is of the form: zone::parent_zone, category::posts::tags

Instance Attribute Summary

Attributes inherited from ForeignAssociationChain

#associations, #model, #selection_path, #target_model

Instance Method Summary collapse

Methods inherited from ForeignAssociationChain

#_assert_association, #_init_association, #_init_associations, #initialize

Constructor Details

This class inherits a constructor from Babik::Association::ForeignAssociationChain

Instance Method Details

#_association_pass(association_i) ⇒ ActiveRecord::Base

Each one of the association

Parameters:

  • association_i (AssociationReflection)

    ith association.

Returns:

  • (ActiveRecord::Base)

    target model of ith association.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/babik/queryset/lib/association/select_related_association_chain.rb', line 17

def _association_pass(association_i)
  # To one relationship
  if association_i.belongs_to? || association_i.has_one?
    @associations << association_i
    associated_model_i = association_i.klass
    @target_model = associated_model_i
    return @target_model
  end
  raise "Bad association path: #{association_i.name} in model #{association_i.klass} " \
        "is not belongs_to or has_one when constructing select_related for #{@model} objects"
end