From 12ad618981f173fe672d0bde31518376c8a8f2b0 Mon Sep 17 00:00:00 2001 From: clocksarestupid Date: Mon, 26 Jul 2010 15:42:58 -0700 Subject: [PATCH 1/2] Fixed incorrect join SQL being generated with a query similar to Author.find(:all, :include => [:books, {:books => :authors}] [#5181 state:resolved] --- activerecord/lib/active_record/associations.rb | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 1b9b725..c1f4718 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1925,7 +1925,8 @@ module ActiveRecord def ==(other) other.class == self.class && other.active_record == active_record && - other.table_joins == table_joins + other.table_joins == table_joins && + other.aliased_table_name == aliased_table_name end def aliased_prefix @@ -1997,7 +1998,8 @@ module ActiveRecord def ==(other) other.class == self.class && other.reflection == reflection && - other.parent == parent + other.parent == parent && + other.aliased_table_name == aliased_table_name end def find_parent_in(other_join_dependency) -- 1.7.1 From 9e0be1defb139db9f67a2d3056e57dab121305a7 Mon Sep 17 00:00:00 2001 From: clocksarestupid Date: Mon, 26 Jul 2010 16:23:01 -0700 Subject: [PATCH 2/2] Added test case for equality check. It fails when the change isn't applied and passes when it is. --- activerecord/test/cases/relations_test.rb | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index cb252d5..21876e3 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -10,6 +10,9 @@ require 'models/entrant' require 'models/developer' require 'models/company' require 'models/bird' +require 'models/pirate' +require 'models/ship' +require 'models/ship_part' class RelationTest < ActiveRecord::TestCase fixtures :authors, :topics, :entrants, :developers, :companies, :developers_projects, :accounts, :categories, :categorizations, :posts, :comments, @@ -272,6 +275,9 @@ class RelationTest < ActiveRecord::TestCase assert posts.first.author assert posts.first.comments.first end + assert_queries(1) do + assert Pirate.includes(:ship).includes(:ship => :parts).where("ship_parts.name=#{ShipPart.quote_value('plank')}").to_a + end end def test_default_scope_with_conditions_string -- 1.7.1