aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-01-12 20:32:11 +0100
committerPiotr Sarnacki <drogus@gmail.com>2012-01-12 20:39:12 +0100
commit6951014c05fa64f533072d21dc7e4c55f59162d4 (patch)
treec0bfb58e9273544f333f9d4818389f5c187c53a5 /activerecord/lib
parent84d633a0b3e74ded1daae58a10508122c2a57879 (diff)
downloadrails-6951014c05fa64f533072d21dc7e4c55f59162d4.tar.gz
rails-6951014c05fa64f533072d21dc7e4c55f59162d4.tar.bz2
rails-6951014c05fa64f533072d21dc7e4c55f59162d4.zip
Fix table_name in ActiveRecord with more than one abstract ancestors
When subclassing abstract_class table_name should be always computed based on class name, no matter if superclass is subclassing base or another abstract_class. So: class FirstAbstract < ActiveRecord::Base self.abstract_class = true end class SecondAbstract < FirstAbstract self.abstract_class = true end class Post < SecondAbstract self.table_name #=> 'posts' (not 'second_abstracts') end
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/model_schema.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index c1a8583119..261f6fa974 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -128,10 +128,14 @@ module ActiveRecord
# Computes the table name, (re)sets it internally, and returns it.
def reset_table_name #:nodoc:
- if active_record_super.abstract_class?
+ if abstract_class?
+ self.table_name = if active_record_super == Base || active_record_super.abstract_class?
+ nil
+ else
+ active_record_super.table_name
+ end
+ elsif active_record_super.abstract_class?
self.table_name = active_record_super.table_name || compute_table_name
- elsif abstract_class?
- self.table_name = active_record_super == Base ? nil : active_record_super.table_name
else
self.table_name = compute_table_name
end