Class: Alchemy::EagerLoading

Inherits:
Object
  • Object
show all
Defined in:
app/models/alchemy/eager_loading.rb

Overview

Eager loading parameters for loading pages

Constant Summary collapse

PAGE_VERSIONS =
%i[draft_version public_version]

Class Method Summary collapse

Class Method Details

.page_includes(version: :public_version) ⇒ Array

Eager loading parameters for ActiveRecord::Base.includes

Pass this to includes whereever you load an Page

Alchemy::Page.includes(Alchemy::EagerLoading.page_includes).find_by(urlname: "my-page")

Parameters:

  • version (Symbol) (defaults to: :public_version)

    Type of page version to eager load

Returns:

  • (Array)

Raises:


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/alchemy/eager_loading.rb', line 17

def page_includes(version: :public_version)
  raise UnsupportedPageVersion unless version.in? PAGE_VERSIONS

  [
    :tags,
    {
      language: :site,
      version => {
        elements: [
          :page,
          :touchable_pages,
          {
            ingredients: :related_object,
            contents: :essence,
          },
        ],
      },
    },
  ]
end