diff options
author | Rick Olson <technoweenie@gmail.com> | 2006-12-19 03:10:39 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2006-12-19 03:10:39 +0000 |
commit | 41466a4c83e3e590b580d5d2cbc5869e601e7599 (patch) | |
tree | 2bb9c1b4274a3efa6f599f36caf2a63971765591 /activerecord | |
parent | d68f559640fcfa41174f544c38c9ac4aff216a26 (diff) | |
download | rails-41466a4c83e3e590b580d5d2cbc5869e601e7599.tar.gz rails-41466a4c83e3e590b580d5d2cbc5869e601e7599.tar.bz2 rails-41466a4c83e3e590b580d5d2cbc5869e601e7599.zip |
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]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5744 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/inheritance_test.rb | 17 |
3 files changed, 18 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index ddfb883e5f..95cae514ac 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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] diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 5c1e796cfd..05eaf7b458 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1569,7 +1569,7 @@ module ActiveRecord 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| diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb index 6d559d8539..20f9225004 100755 --- a/activerecord/test/inheritance_test.rb +++ b/activerecord/test/inheritance_test.rb @@ -4,7 +4,7 @@ require 'fixtures/project' 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 @@ class InheritanceTest < Test::Unit::TestCase 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 @@ class InheritanceTest < Test::Unit::TestCase 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 |