diff --git a/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb b/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb index edfff82b1..fd836fa14 100644 --- a/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +++ b/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb @@ -16,9 +16,5 @@ def initialize(reflection, children, polymorphic_class = nil, join_type = Arel:: super(reflection, children) end end - - def ==(other) - base_klass == other.base_klass - end end end diff --git a/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb b/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb index 386c25ee7..42eaf47a8 100644 --- a/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +++ b/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb @@ -66,9 +66,5 @@ def join_constraints_with_tables(foreign_table, foreign_klass, join_type, alias_ joins end - - def ==(other) - base_klass == other.base_klass - end end end diff --git a/spec/polyamorous/activerecord_compatibility_spec.rb b/spec/polyamorous/activerecord_compatibility_spec.rb new file mode 100644 index 000000000..614c338d9 --- /dev/null +++ b/spec/polyamorous/activerecord_compatibility_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +module Polyamorous + describe "ActiveRecord Compatibility" do + it 'works with self joins and includes' do + trade_account = Account.create! + Account.create!(trade_account: trade_account) + + accounts = Account.joins(:trade_account).includes(:trade_account, :agent_account) + account = accounts.first + + expect(account.agent_account).to be_nil + end + end +end diff --git a/spec/polyamorous/join_association_spec.rb b/spec/polyamorous/join_association_spec.rb index 17335bd1c..04be060f9 100644 --- a/spec/polyamorous/join_association_spec.rb +++ b/spec/polyamorous/join_association_spec.rb @@ -12,11 +12,6 @@ module Polyamorous subject { new_join_association(reflection, parent.children, Person) } - it 'respects polymorphism on equality test' do - expect(subject).to eq new_join_association(reflection, parent.children, Person) - expect(subject).not_to eq new_join_association(reflection, parent.children, Article) - end - it 'leaves the original reflection intact for thread safety' do reflection.instance_variable_set(:@klass, Article) join_association diff --git a/spec/support/schema.rb b/spec/support/schema.rb index f7f7749e5..f818d8c7b 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -199,6 +199,11 @@ class Note < ActiveRecord::Base belongs_to :notable, polymorphic: true end +class Account < ActiveRecord::Base + belongs_to :agent_account, class_name: "Account" + belongs_to :trade_account, class_name: "Account" +end + module Schema def self.create ActiveRecord::Migration.verbose = false @@ -257,6 +262,11 @@ def self.create t.integer :target_person_id t.integer :article_id end + + create_table :accounts, force: true do |t| + t.belongs_to :agent_account + t.belongs_to :trade_account + end end 10.times do