Permalink
Browse files

Fix sequence name with abstract classes.

  • Loading branch information...
1 parent 91a3e92 commit 82ae5c40ea29eecc2c0d017ffc7c2f2a23a7e21f @ebeigarts ebeigarts committed Dec 4, 2011
Showing with 12 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/base.rb
  2. +10 −0 activerecord/test/cases/base_test.rb
View
4 activerecord/lib/active_record/base.rb
@@ -721,10 +721,10 @@ def set_inheritance_column(value = nil, &block) #:nodoc:
end
def sequence_name
- if superclass == Base
+ if base_class == self
@sequence_name ||= reset_sequence_name
else
- (@sequence_name ||= nil) || superclass.sequence_name
+ (@sequence_name ||= nil) || base_class.sequence_name
end
end
View
10 activerecord/test/cases/base_test.rb
@@ -1601,6 +1601,16 @@ def test_original_sequence_name
end
end
+ def test_sequence_name_with_abstract_class
+ ak = Class.new(ActiveRecord::Base)
+ ak.abstract_class = true
+ k = Class.new(ak)
+ k.table_name = "projects"
+ orig_name = k.sequence_name
+ return skip "sequences not supported by db" unless orig_name
+ assert_equal k.reset_sequence_name, orig_name
+ end
+
def test_count_with_join
res = Post.count_by_sql "SELECT COUNT(*) FROM posts LEFT JOIN comments ON posts.id=comments.post_id WHERE posts.#{QUOTED_TYPE} = 'Post'"

0 comments on commit 82ae5c4

Please sign in to comment.