Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use replace_methods: false in batch loaders #29

Merged
merged 1 commit into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ams_lazy_relationships/loaders/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(model_class_name, association_name)
# @param block [Proc] a block to execute when data is evaluated.
# Loaded data is yielded as a block argument.
def load(record, &block)
BatchLoader.for(record).batch(key: batch_key) do |records, loader|
BatchLoader.for(record).batch(key: batch_key, replace_methods: false) do |records, loader|
data = load_data(records, loader)

block&.call(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/ams_lazy_relationships/loaders/direct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(relationship_name, &load_block)
# @param block [Proc] a block to execute when data is evaluated.
# Loaded data is yielded as a block argument.
def load(record, &block)
BatchLoader.for(record).batch(key: cache_key(record)) do |records, loader|
BatchLoader.for(record).batch(key: cache_key(record), replace_methods: false) do |records, loader|
data = []
records.each do |r|
value = calculate_value(r)
Expand Down
2 changes: 1 addition & 1 deletion lib/ams_lazy_relationships/loaders/simple_belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(
# @param block [Proc] a block to execute when data is evaluated
# Loaded data is yielded as a block argument.
def load(record, &block)
BatchLoader.for(record).batch(key: cache_key(record)) do |records, loader|
BatchLoader.for(record).batch(key: cache_key(record), replace_methods: false) do |records, loader|
data = load_data(records)

block&.call(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/ams_lazy_relationships/loaders/simple_has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(association_class_name, foreign_key:)
# Loaded data is yielded as a block argument.
def load(record, &block)
key = "#{record.class}/#{association_class_name}"
BatchLoader.for(record).batch(key: key) do |records, loader|
BatchLoader.for(record).batch(key: key, replace_methods: false) do |records, loader|
data = load_data(records)

block&.call(data)
Expand Down