aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJenner LaFave <jenner@jfave.com>2014-05-02 18:00:53 -0700
committerJenner LaFave <jenner@jfave.com>2014-05-05 12:41:26 -0700
commit5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c (patch)
treee380fd719ac1f68113b32772c0bf82b2ddfd61ed /activerecord/lib
parent4efb0f373047c44249bc6542fdf9969e4c63dd88 (diff)
downloadrails-5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c.tar.gz
rails-5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c.tar.bz2
rails-5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c.zip
Add support for module-level table_suffix in models
This makes table_name_suffix work the same as table_name_prefix when using namespaced models. Pretty much the same as 67d1cec.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/model_schema.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index dc5ff02882..002bd16976 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -29,6 +29,10 @@ module ActiveRecord
# :singleton-method:
# Works like +table_name_prefix+, but appends instead of prepends (set to "_basecamp" gives "projects_basecamp",
# "people_basecamp"). By default, the suffix is the empty string.
+ #
+ # If you are organising your models within modules, you can add a suffix to the models within
+ # a namespace by defining a singleton method in the parent module called table_name_suffix which
+ # returns your chosen suffix.
class_attribute :table_name_suffix, instance_writer: false
self.table_name_suffix = ""
@@ -153,6 +157,10 @@ module ActiveRecord
(parents.detect{ |p| p.respond_to?(:table_name_prefix) } || self).table_name_prefix
end
+ def full_table_name_suffix #:nodoc:
+ (parents.detect {|p| p.respond_to?(:table_name_suffix) } || self).table_name_suffix
+ end
+
# Defines the name of the table column which will store the class name on single-table
# inheritance situations.
#
@@ -337,7 +345,8 @@ module ActiveRecord
contained = contained.singularize if parent.pluralize_table_names
contained += '_'
end
- "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}"
+
+ "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{full_table_name_suffix}"
else
# STI subclasses always use their superclass' table.
base.table_name