1
0
Fork 0
mirror of https://github.com/activerecord-hackery/ransack.git synced 2022-11-09 13:47:45 -05:00

Merge pull request #939 from y-yagi/fix_duplicate_alias_error

Do not override `join_constraints`
This commit is contained in:
Greg Molnar 2018-08-07 08:35:11 +02:00 committed by GitHub
commit 6440d88a0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,63 +48,6 @@ module Polyamorous
end
end
# Replaces ActiveRecord::Associations::JoinDependency#join_constraints
#
# This internal method was changed in Rails 5.0 by commit
# https://github.com/rails/rails/commit/e038975 which added
# left_outer_joins (see #make_polyamorous_left_outer_joins below) and added
# passing an additional argument, `join_type`, to #join_constraints.
#
def join_constraints(joins_to_add, join_type, alias_tracker)
@alias_tracker = alias_tracker
construct_tables!(join_root)
joins = join_root.children.flat_map { |child|
if join_type == Arel::Nodes::OuterJoin
make_polyamorous_left_outer_joins join_root, child
else
make_polyamorous_inner_joins join_root, child
end
}
joins.concat joins_to_add.flat_map { |oj|
construct_tables!(oj.join_root)
if join_root.match? oj.join_root
walk(join_root, oj.join_root)
else
make_join_constraints(oj.join_root, join_type)
end
}
end
# Replaces ActiveRecord::Associations::JoinDependency#make_left_outer_joins,
# a new method that was added in Rails 5.0 with the following commit:
# https://github.com/rails/rails/commit/e038975
#
def make_polyamorous_left_outer_joins(parent, child)
join_type = Arel::Nodes::OuterJoin
info = make_constraints parent, child, join_type
info + child.children.flat_map { |c|
make_polyamorous_left_outer_joins(child, c)
}
end
# Replaces ActiveRecord::Associations::JoinDependency#make_inner_joins
#
def make_polyamorous_inner_joins(parent, child)
tables = child.tables
join_type = child.join_type || Arel::Nodes::InnerJoin
info = make_constraints parent, child, join_type
info + child.children.flat_map { |c|
make_polyamorous_inner_joins(child, c)
}
end
private :make_polyamorous_inner_joins, :make_polyamorous_left_outer_joins
module ClassMethods
# Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
#