aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorchapmajs <glitch@glitchwrks.com>2013-04-30 23:11:49 -0300
committerTakehiro Adachi <takehiro0740@gmail.com>2013-06-26 14:55:18 +0900
commit839efc5b6d754697682d5b2bd34ef28b2c5d2adf (patch)
tree9c714d14456c766dd3441e4ef66d14f419f4ac86 /activerecord
parentb23e0d66394a7c5442cc1ebbf4f1f2441878a8d2 (diff)
downloadrails-839efc5b6d754697682d5b2bd34ef28b2c5d2adf.tar.gz
rails-839efc5b6d754697682d5b2bd34ef28b2c5d2adf.tar.bz2
rails-839efc5b6d754697682d5b2bd34ef28b2c5d2adf.zip
Allow global override of default STI inheritance column
This change fixes a bug by which 3.2-STABLE users can't globally override the default STI inheritance column with `ActiveRecord::Base.inheritance_column = 'some_column'`. 3.2-STABLE users are forced to use a deprecated method or monkey patch it otherwise. Test case written by tkhr <takehiro0740@gmail.com>.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/model_schema.rb2
-rw-r--r--activerecord/test/cases/inheritance_test.rb23
3 files changed, 29 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index c673a278f6..3c38b47d2e 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -5,6 +5,11 @@
*Janko Marohnić*
+* Fix a bug that prevented the use of the default STI inheritance column
+ (ActiveRecord::Base.inheritance_column = 'some_column'.)
+
+ *chapmajs + Takehiro Adachi*
+
* Fix mysql2 adapter raises the correct exception when executing a query on a
closed connection.
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index e10e6b4aa8..40cc8dcd69 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -159,7 +159,7 @@ module ActiveRecord
# The name of the column containing the object's class when Single Table Inheritance is used
def inheritance_column
if self == Base
- 'type'
+ (@inheritance_column ||= nil) || 'type'
else
(@inheritance_column ||= nil) || superclass.inheritance_column
end
diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb
index 54c9152c06..99a252a389 100644
--- a/activerecord/test/cases/inheritance_test.rb
+++ b/activerecord/test/cases/inheritance_test.rb
@@ -290,3 +290,26 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase
ActiveRecord::Base.store_full_sti_class = true
end
end
+
+
+class GlobalInheritanceColumnTest < ActiveRecord::TestCase
+ fixtures :companies
+
+ setup do
+ @inheritance_column = ActiveRecord::Base.inheritance_column
+ end
+
+ teardown do
+ ActiveRecord::Base.inheritance_column = @inheritance_column
+ end
+
+ def test_changing_global_inheritance_column
+ ActiveRecord::Base.inheritance_column = 'ruby_type'
+
+ firm = Firm.create('name' => 'FirmWithAltInheritanceColumn')
+ assert_equal 'Firm', firm.ruby_type
+
+ assert_equal 'ruby_type', Company.inheritance_column
+ assert_equal 'ruby_type', Firm.inheritance_column
+ end
+end