class Babik::Selection::Path::ForeignPath

Foreign path A foreign path is a succession of associations ending optionally in an operator if operator is not present, equal is supposed.

Constants

OPERATOR_SEPARATOR
RELATIONSHIP_SEPARATOR

Attributes

model[R]
selected_field[R]
selection_path[R]

Public Class Methods

new(model, selection_path) click to toggle source

Construct a foreign path A foreign path will be used with a value as a foreign selection to filter a model with foreign conditions @param model [ActiveRecord::Base] model that is the object of the foreign path. @param selection_path [String, Symbol] Association path with an operator. e.g.:

posts::category__in
author::posts::tags
creation_at__date__gte
# File lib/babik/queryset/lib/selection/path/foreign_path.rb, line 32
def initialize(model, selection_path)
  @model = model
  @selection_path = selection_path.dup
  @association_path = selection_path.to_s.split(RELATIONSHIP_SEPARATOR)
  selection_path = @association_path.pop
  @selected_field, @operator = selection_path.split(OPERATOR_SEPARATOR)
  @operator ||= 'equal'
  _initialize_associations
end

Public Instance Methods

_initialize_associations() click to toggle source

Initialize associations

# File lib/babik/queryset/lib/selection/path/foreign_path.rb, line 43
def _initialize_associations
  @association_chain = Babik::Association::ForeignAssociationChain.new(@model, @association_path, @selection_path)
  @association_joiner = Babik::QuerySet::Join::AssociationJoiner.new(@association_chain.associations)
end