aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-06-15 00:46:44 -0400
committerNeeraj Singh <neerajdotname@gmail.com>2010-06-15 00:46:44 -0400
commit5e60e6571384a809598f3118fdc02dac1fd9d7b8 (patch)
tree3cfccbc36f0133124181ab965480a1352d86ca79 /activerecord/lib/active_record/base.rb
parent51a9703b1e80caa30d699f30615f023079874623 (diff)
parent1a50cc31639f35fd82a4a24821b9fc49dc7eadc9 (diff)
downloadrails-5e60e6571384a809598f3118fdc02dac1fd9d7b8.tar.gz
rails-5e60e6571384a809598f3118fdc02dac1fd9d7b8.tar.bz2
rails-5e60e6571384a809598f3118fdc02dac1fd9d7b8.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb39
1 files changed, 21 insertions, 18 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 63ab6efae2..3b6ffa46f2 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -14,6 +14,7 @@ require 'active_support/core_ext/hash/slice'
require 'active_support/core_ext/string/behavior'
require 'active_support/core_ext/kernel/singleton_class'
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/module/introspection'
require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/object/blank'
require 'arel'
@@ -647,29 +648,14 @@ module ActiveRecord #:nodoc:
reset_table_name
end
+ # Returns a quoted version of the table name, used to construct SQL statements.
def quoted_table_name
@quoted_table_name ||= connection.quote_table_name(table_name)
end
+ # Computes the table name, (re)sets it internally, and returns it.
def reset_table_name #:nodoc:
- base = base_class
-
- name =
- # STI subclasses always use their superclass' table.
- unless self == base
- base.table_name
- else
- # Nested classes are prefixed with singular parent table name.
- if parent < ActiveRecord::Base && !parent.abstract_class?
- contained = parent.table_name
- contained = contained.singularize if parent.pluralize_table_names
- contained << '_'
- end
- name = "#{full_table_name_prefix}#{contained}#{undecorated_table_name(base.name)}#{table_name_suffix}"
- end
-
- set_table_name(name)
- name
+ self.table_name = compute_table_name
end
def full_table_name_prefix #:nodoc:
@@ -1001,6 +987,23 @@ module ActiveRecord #:nodoc:
table_name
end
+ # Computes and returns a table name according to default conventions.
+ 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?
+ contained = parent.table_name
+ contained = contained.singularize if parent.pluralize_table_names
+ contained << '_'
+ end
+ "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}"
+ else
+ # STI subclasses always use their superclass' table.
+ base.table_name
+ end
+ end
+
# Enables dynamic finders like <tt>find_by_user_name(user_name)</tt> and <tt>find_by_user_name_and_password(user_name, password)</tt>
# that are turned into <tt>where(:user_name => user_name).first</tt> and <tt>where(:user_name => user_name, :password => :password).first</tt>
# respectively. Also works for <tt>all</tt> by using <tt>find_all_by_amount(50)</tt> that is turned into <tt>where(:amount => 50).all</tt>.