-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract common eager loading parameters into Class
This helps keep the duplication down.
- Loading branch information
Showing
4 changed files
with
39 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Alchemy | ||
# Eager loading parameters for loading pages | ||
class EagerLoading | ||
class << self | ||
# Eager loading parameters for {ActiveRecord::Base.includes} | ||
# | ||
# Pass this to +includes+ whereever you load an {Alchemy::Page} | ||
# | ||
# Alchemy::Page.includes(Alchemy::EagerLoading.page_includes).find_by(urlname: "my-page") | ||
# | ||
# | ||
# @param version [Symbol] Type of page version to eager load | ||
# @return [Array] | ||
def page_includes(version: :public_version) | ||
[ | ||
:tags, | ||
{ | ||
language: :site, | ||
version => { | ||
elements: [ | ||
:page, | ||
:touchable_pages, | ||
{ | ||
ingredients: :related_object, | ||
contents: :essence, | ||
}, | ||
], | ||
}, | ||
}, | ||
] | ||
end | ||
end | ||
end | ||
end |