Permalink
Browse files

Support nested AR::Models

  • Loading branch information...
1 parent 15fbf5b commit 0e3e34f0eba32ebc561f56e8eda22ed9b8ad76c7 @jonleighton jonleighton committed Dec 24, 2011
@@ -291,7 +291,7 @@ def compute_table_name
base = base_class
if self == base
# Nested classes are prefixed with singular parent table name.
- if parent < ActiveRecord::Base && !parent.abstract_class?
+ if parent < ActiveRecord::Model && !parent.abstract_class?
contained = parent.table_name
contained = contained.singularize if parent.pluralize_table_names
contained += '_'
@@ -29,6 +29,10 @@ def test_predicate_builder
assert_equal "Bob", Teapot.where(:id => [t]).first.name
assert_equal "Bob", Teapot.where(:id => t).first.name
end
+
+ def test_nested_model
+ assert_equal "ceiling_teapots", Ceiling::Teapot.table_name
+ end
end
class InclusionUnitTest < ActiveRecord::TestCase
@@ -22,3 +22,11 @@ class CoolTeapot < OMFGIMATEAPOT
include ActiveRecord::Model
self.table_name = "teapots"
end
+
+class Ceiling
+ include ActiveRecord::Model
+
+ class Teapot
+ include ActiveRecord::Model
+ end
+end

0 comments on commit 0e3e34f

Please sign in to comment.