Skip to content

Commit

Permalink
add rails 6 injector
Browse files Browse the repository at this point in the history
  • Loading branch information
ncliffor committed Dec 17, 2021
1 parent ba46270 commit 72f2af0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/baby_squeel/active_record/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def when_having(&block)
# BabySqueel::Join nodes.
if ::ActiveRecord::VERSION::MAJOR == 6
def build_joins(*args)
args[1] = BabySqueel::JoinDependency::Injector.new(args.second)
args[1] = BabySqueel::JoinDependency::Injector6_0.new(args.second)
super *args
end
elsif ::ActiveRecord::VERSION::MAJOR == 5 && ::ActiveRecord::VERSION::MINOR >= 2
Expand Down
23 changes: 23 additions & 0 deletions lib/baby_squeel/join_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ def group_by
end
end

# This class allows BabySqueel to slip custom
# joins_values into Active Record's JoinDependency
class Injector6_0 < Array # :nodoc:
# https://github.com/rails/rails/pull/36805/files
# This commit changed group_by to each
def each(&block)
super do |join|
if block.binding.local_variables.include?(:buckets)
buckets = block.binding.local_variable_get(:buckets)

case join
when BabySqueel::Join
buckets[:association_join] << join
else
block.call(join)
end
else
block.call(join)
end
end
end
end

class Builder # :nodoc:
attr_reader :join_dependency

Expand Down

0 comments on commit 72f2af0

Please sign in to comment.