Permalink
Browse files

fix faulty inheritance tests and that eager loading grabs the wrong i…

…nheritance column when the class of your association is an STI subclass. Closes #6859 [protocool]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5744 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent d68f559 commit 41466a4c83e3e590b580d5d2cbc5869e601e7599 @technoweenie technoweenie committed Dec 19, 2006
Showing with 18 additions and 3 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +1 −1 activerecord/lib/active_record/associations.rb
  3. +15 −2 activerecord/test/inheritance_test.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* fix faulty inheritance tests and that eager loading grabs the wrong inheritance column when the class of your association is an STI subclass. Closes #6859 [protocool]
+
* Consolidated different create and create! versions to call through to the base class with scope. This fixes inconsistencies, especially related to protected attribtues. Closes #5847 [Alexander Dymo, Tobias Luetke]
* find supports :lock with :include. Check whether your database allows SELECT ... FOR UPDATE with outer joins before using. #6764 [vitaly, Jeremy Kemper]
@@ -1569,7 +1569,7 @@ def association_join
end || ''
join << %(AND %s.%s = %s ) % [
aliased_table_name,
- reflection.active_record.connection.quote_column_name(reflection.active_record.inheritance_column),
+ reflection.active_record.connection.quote_column_name(klass.inheritance_column),
klass.quote_value(klass.name.demodulize)] unless klass.descends_from_active_record?
[through_reflection, reflection].each do |ref|
@@ -4,7 +4,7 @@
require 'fixtures/subscriber'
class InheritanceTest < Test::Unit::TestCase
- fixtures :companies, :projects, :subscribers
+ fixtures :companies, :projects, :subscribers, :accounts
def test_a_bad_type_column
#SQLServer need to turn Identity Insert On before manually inserting into the Identity column
@@ -134,6 +134,18 @@ def test_alt_complex_inheritance
test_complex_inheritance
switch_to_default_inheritance_column
end
+
+ def test_eager_load_belongs_to_something_inherited
+ account = Account.find(1, :include => :firm)
+ assert_not_nil account.instance_variable_get("@firm"), "nil proves eager load failed"
+ end
+
+ def test_alt_eager_loading
+ switch_to_alt_inheritance_column
+ test_eager_load_belongs_to_something_inherited
+ switch_to_default_inheritance_column
+ ActiveRecord::Base.logger.debug "cocksucker"
+ end
def test_inheritance_without_mapping
assert_kind_of SpecialSubscriber, SpecialSubscriber.find("webster132")
@@ -148,9 +160,10 @@ def switch_to_alt_inheritance_column
c.save
end
[ Company, Firm, Client].each { |klass| klass.reset_column_information }
- def Company.inheritance_column; @inheritance_column ||= "ruby_type"; end
+ Company.set_inheritance_column('ruby_type')
end
def switch_to_default_inheritance_column
[ Company, Firm, Client].each { |klass| klass.reset_column_information }
+ Company.set_inheritance_column('type')
end
end

1 comment on commit 41466a4

nate commented on 41466a4 Jan 9, 2009

naughty logger

Please sign in to comment.