Module: Babik::QuerySet::RelatedSelector

Included in:
AbstractBase
Defined in:
lib/babik/queryset/mixins/related_selector.rb

Overview

select_related functionality of QuerySet

Instance Method Summary collapse

Instance Method Details

#select_related!(association_paths) ⇒ Object

Load the related objects of each model object specified by the association_paths

e.g.

  • User.objects.filter(first_name: ‘Julius’).select_related(:group)

  • User.objects.filter(first_name: ‘Cassius’).select_related([:group, :zone])

  • Post.objects.select_related(:author)

Parameters:

  • association_paths (Array<Symbol>, Symbol)

    Array of association paths of belongs_to and has_one related objects. A passed symbol will be considered as an array of one symbol. That is, select_related(:group) is equal to select_related()



20
21
22
23
# File 'lib/babik/queryset/mixins/related_selector.rb', line 20

def select_related!(association_paths)
  @_select_related = Babik::QuerySet::SelectRelated.new(@model, association_paths)
  self
end