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

Remove unused/useless constant aliases #953

Merged
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
26 changes: 4 additions & 22 deletions lib/polyamorous.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
if defined?(::ActiveRecord)
module Polyamorous
if defined?(Arel::InnerJoin)
InnerJoin = Arel::InnerJoin
OuterJoin = Arel::OuterJoin
else
InnerJoin = Arel::Nodes::InnerJoin
OuterJoin = Arel::Nodes::OuterJoin
end
InnerJoin = Arel::Nodes::InnerJoin
OuterJoin = Arel::Nodes::OuterJoin

if defined?(::ActiveRecord::Associations::JoinDependency)
JoinDependency = ::ActiveRecord::Associations::JoinDependency
JoinAssociation = ::ActiveRecord::Associations::JoinDependency::JoinAssociation
JoinBase = ::ActiveRecord::Associations::JoinDependency::JoinBase
else
JoinDependency = ::ActiveRecord::Associations::ClassMethods::JoinDependency
JoinAssociation = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
JoinBase = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase
end
JoinDependency = ::ActiveRecord::Associations::JoinDependency
JoinAssociation = ::ActiveRecord::Associations::JoinDependency::JoinAssociation
end

require 'polyamorous/tree_node'
Expand All @@ -33,10 +21,4 @@ module Polyamorous
Polyamorous::JoinDependency.send(:prepend, Polyamorous::JoinDependencyExtensions)
Polyamorous::JoinDependency.singleton_class.send(:prepend, Polyamorous::JoinDependencyExtensions::ClassMethods)
Polyamorous::JoinAssociation.send(:prepend, Polyamorous::JoinAssociationExtensions)

Polyamorous::JoinBase.class_eval do
if method_defined?(:active_record)
alias_method :base_klass, :active_record
end
end
end
17 changes: 6 additions & 11 deletions lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ module Adapters
module ActiveRecord
class Context < ::Ransack::Context

# Because the AR::Associations namespace is insane
if defined? ::ActiveRecord::Associations::JoinDependency
JoinDependency = ::ActiveRecord::Associations::JoinDependency
end

def initialize(object, options = {})
super
if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2
Expand Down Expand Up @@ -235,19 +230,19 @@ def build_joins(relation)
join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)

if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2_0
join_dependency = JoinDependency.new(relation.klass, association_joins, join_list)
join_dependency = Polyamorous::JoinDependency.new(relation.klass, association_joins, join_list)
join_nodes.each do |join|
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
end
elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
join_dependency = JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker)
join_nodes.each do |join|
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
end
else
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
join_dependency = JoinDependency.new(relation.klass, relation.table, association_joins)
join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
join_nodes.each do |join|
join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
Expand Down Expand Up @@ -276,23 +271,23 @@ def find_association(name, parent = @base, klass = nil)

def build_association(name, parent = @base, klass = nil)
if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2_0
jd = JoinDependency.new(
jd = Polyamorous::JoinDependency.new(
parent.base_klass,
Polyamorous::Join.new(name, @join_type, klass),
[]
)
found_association = jd.join_root.children.last
elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, parent.table.name, [])
jd = JoinDependency.new(
jd = Polyamorous::JoinDependency.new(
parent.base_klass,
parent.base_klass.arel_table,
Polyamorous::Join.new(name, @join_type, klass),
alias_tracker
)
found_association = jd.instance_variable_get(:@join_root).children.last
else
jd = JoinDependency.new(
jd = Polyamorous::JoinDependency.new(
parent.base_klass,
parent.base_klass.arel_table,
Polyamorous::Join.new(name, @join_type, klass),
Expand Down