1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #3851 from ebeigarts/fix_sequence_name

Fix sequence name with abstract classes.
This commit is contained in:
Jon Leighton 2011-12-04 15:19:17 -08:00
commit 4ded0dd2de
2 changed files with 12 additions and 2 deletions

View file

@ -722,10 +722,10 @@ module ActiveRecord #: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 file

@ -1601,6 +1601,16 @@ class BasicsTest < ActiveRecord::TestCase
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'"