mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Cache inheritance_column. Closes #6592.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5474 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
0342393b30
commit
9d2da04680
4 changed files with 22 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Cache inheritance_column. #6592 [Stefan Kaes]
|
||||
|
||||
* Firebird: decimal/numeric support. #6408 [macrnic]
|
||||
|
||||
* make add_order a tad faster. #6567 [Stefan Kaes]
|
||||
|
|
|
@ -1170,7 +1170,7 @@ module ActiveRecord
|
|||
|
||||
sql << "GROUP BY #{options[:group]} " if options[:group]
|
||||
|
||||
add_order!(sql, options[:order])
|
||||
add_order!(sql, options[:order], scope)
|
||||
add_limit!(sql, options, scope) if using_limitable_reflections?(join_dependency.reflections)
|
||||
|
||||
return sanitize_sql(sql)
|
||||
|
|
|
@ -648,9 +648,10 @@ module ActiveRecord #:nodoc:
|
|||
key
|
||||
end
|
||||
|
||||
# Defines the column name for use with single table inheritance -- can be overridden in subclasses.
|
||||
# Defines the column name for use with single table inheritance
|
||||
# -- can be set in subclasses like so: self.inheritance_column = "type_id"
|
||||
def inheritance_column
|
||||
"type"
|
||||
@inheritance_column ||= "type".freeze
|
||||
end
|
||||
|
||||
# Lazy-set the sequence name to the connection's default. This method
|
||||
|
@ -800,7 +801,7 @@ module ActiveRecord #:nodoc:
|
|||
# Resets all the cached information about columns, which will cause them to be reloaded on the next request.
|
||||
def reset_column_information
|
||||
read_methods.each { |name| undef_method(name) }
|
||||
@column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @read_methods = nil
|
||||
@column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @read_methods = @inheritance_column = nil
|
||||
end
|
||||
|
||||
def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodoc:
|
||||
|
@ -1057,7 +1058,7 @@ module ActiveRecord #:nodoc:
|
|||
|
||||
# Ignore type if no column is present since it was probably
|
||||
# pulled in from a sloppy join.
|
||||
unless self.columns_hash.include?(inheritance_column)
|
||||
unless columns_hash.include?(inheritance_column)
|
||||
allocate
|
||||
|
||||
else
|
||||
|
|
|
@ -30,6 +30,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_inheritance_find
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_find
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_inheritance_find_all
|
||||
|
@ -41,6 +42,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_inheritance_find_all
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_find_all
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_inheritance_save
|
||||
|
@ -55,6 +57,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_inheritance_save
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_save
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_inheritance_condition
|
||||
|
@ -66,6 +69,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_inheritance_condition
|
||||
switch_to_alt_inheritance_column
|
||||
test_inheritance_condition
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_finding_incorrect_type_data
|
||||
|
@ -76,6 +80,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_finding_incorrect_type_data
|
||||
switch_to_alt_inheritance_column
|
||||
test_finding_incorrect_type_data
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_update_all_within_inheritance
|
||||
|
@ -87,6 +92,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_update_all_within_inheritance
|
||||
switch_to_alt_inheritance_column
|
||||
test_update_all_within_inheritance
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_destroy_all_within_inheritance
|
||||
|
@ -98,6 +104,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_destroy_all_within_inheritance
|
||||
switch_to_alt_inheritance_column
|
||||
test_destroy_all_within_inheritance
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_find_first_within_inheritance
|
||||
|
@ -109,6 +116,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_find_first_within_inheritance
|
||||
switch_to_alt_inheritance_column
|
||||
test_find_first_within_inheritance
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_complex_inheritance
|
||||
|
@ -124,6 +132,7 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
def test_alt_complex_inheritance
|
||||
switch_to_alt_inheritance_column
|
||||
test_complex_inheritance
|
||||
switch_to_default_inheritance_column
|
||||
end
|
||||
|
||||
def test_inheritance_without_mapping
|
||||
|
@ -138,7 +147,10 @@ class InheritanceTest < Test::Unit::TestCase
|
|||
c['type'] = nil
|
||||
c.save
|
||||
end
|
||||
|
||||
def Company.inheritance_column() "ruby_type" end
|
||||
[ Company, Firm, Client].each { |klass| klass.reset_column_information }
|
||||
def Company.inheritance_column; @inheritance_column ||= "ruby_type"; end
|
||||
end
|
||||
def switch_to_default_inheritance_column
|
||||
[ Company, Firm, Client].each { |klass| klass.reset_column_information }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue