Class: Babik::Selection::SelectRelatedSelection

Inherits:
Object
  • Object
show all
Defined in:
lib/babik/queryset/lib/selection/select_related_selection.rb

Overview

Abstraction of a selection used in select_related operation

Constant Summary collapse

RELATIONSHIP_SEPARATOR =
Babik::Selection::Config::RELATIONSHIP_SEPARATOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, selection_path) ⇒ SelectRelatedSelection

Returns a new instance of SelectRelatedSelection.



21
22
23
24
25
26
27
28
29
# File 'lib/babik/queryset/lib/selection/select_related_selection.rb', line 21

def initialize(model, selection_path)
  @model = model
  @selection_path = selection_path.dup
  @association_path = selection_path.to_s.split(RELATIONSHIP_SEPARATOR)
  @id = @association_path.join('__')

  _initialize_associations
  @target_model = @association_chain.target_model
end

Instance Attribute Details

#association_pathObject (readonly)

Returns the value of attribute association_path.



16
17
18
# File 'lib/babik/queryset/lib/selection/select_related_selection.rb', line 16

def association_path
  @association_path
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/babik/queryset/lib/selection/select_related_selection.rb', line 16

def id
  @id
end

#modelObject (readonly)

Returns the value of attribute model.



16
17
18
# File 'lib/babik/queryset/lib/selection/select_related_selection.rb', line 16

def model
  @model
end

#selection_pathObject (readonly)

Returns the value of attribute selection_path.



16
17
18
# File 'lib/babik/queryset/lib/selection/select_related_selection.rb', line 16

def selection_path
  @selection_path
end

#target_modelObject (readonly)

Returns the value of attribute target_model.



16
17
18
# File 'lib/babik/queryset/lib/selection/select_related_selection.rb', line 16

def target_model
  @target_model
end

Instance Method Details

#_initialize_associationsObject



31
32
33
34
# File 'lib/babik/queryset/lib/selection/select_related_selection.rb', line 31

def _initialize_associations
  @association_chain = Babik::Association::SelectRelatedAssociationChain.new(@model, @association_path, @selection_path)
  @association_joiner = Babik::QuerySet::Join::AssociationJoiner.new(@association_chain.associations)
end