mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Support nested AR::Models
This commit is contained in:
parent
15fbf5b58b
commit
0e3e34f0eb
3 changed files with 13 additions and 1 deletions
|
@ -291,7 +291,7 @@ module ActiveRecord
|
||||||
base = base_class
|
base = base_class
|
||||||
if self == base
|
if self == base
|
||||||
# Nested classes are prefixed with singular parent table name.
|
# 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 = parent.table_name
|
||||||
contained = contained.singularize if parent.pluralize_table_names
|
contained = contained.singularize if parent.pluralize_table_names
|
||||||
contained += '_'
|
contained += '_'
|
||||||
|
|
|
@ -29,6 +29,10 @@ class BasicInclusionModelTest < ActiveRecord::TestCase
|
||||||
assert_equal "Bob", Teapot.where(:id => [t]).first.name
|
assert_equal "Bob", Teapot.where(:id => [t]).first.name
|
||||||
assert_equal "Bob", Teapot.where(:id => t).first.name
|
assert_equal "Bob", Teapot.where(:id => t).first.name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_nested_model
|
||||||
|
assert_equal "ceiling_teapots", Ceiling::Teapot.table_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class InclusionUnitTest < ActiveRecord::TestCase
|
class InclusionUnitTest < ActiveRecord::TestCase
|
||||||
|
|
|
@ -22,3 +22,11 @@ class CoolTeapot < OMFGIMATEAPOT
|
||||||
include ActiveRecord::Model
|
include ActiveRecord::Model
|
||||||
self.table_name = "teapots"
|
self.table_name = "teapots"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Ceiling
|
||||||
|
include ActiveRecord::Model
|
||||||
|
|
||||||
|
class Teapot
|
||||||
|
include ActiveRecord::Model
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue