diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2010-02-22 10:46:45 +0000 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-28 23:43:28 -0700 |
commit | 67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc (patch) | |
tree | 861e8f3b51c78e2b0aee197cbaf5f189e77666ff /activerecord/lib/active_record | |
parent | 48c1d8c341e1fe09111424131f7d223ad032b7e1 (diff) | |
download | rails-67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc.tar.gz rails-67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc.tar.bz2 rails-67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc.zip |
Add the ability to specify table_name_prefix on individual modules
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 21b89694fc..289c95ad8f 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -338,6 +338,9 @@ module ActiveRecord #:nodoc: # Accessor for the name of the prefix string to prepend to every table name. So if set to "basecamp_", all # table names will be named like "basecamp_projects", "basecamp_people", etc. This is a convenient way of creating a namespace # for tables in a shared database. By default, the prefix is the empty string. + # + # If you are organising your models within modules you can add a prefix to the models within a namespace by defining + # a singleton method in the parent module called table_name_prefix which returns your chosen prefix. cattr_accessor :table_name_prefix, :instance_writer => false @@table_name_prefix = "" @@ -765,7 +768,7 @@ module ActiveRecord #:nodoc: contained = contained.singularize if parent.pluralize_table_names contained << '_' end - name = "#{table_name_prefix}#{contained}#{undecorated_table_name(base.name)}#{table_name_suffix}" + name = "#{modularized_table_name_prefix}#{contained}#{undecorated_table_name(base.name)}#{table_name_suffix}" end @quoted_table_name = nil @@ -773,6 +776,10 @@ module ActiveRecord #:nodoc: name end + def modularized_table_name_prefix #:nodoc: + (parents.detect{ |p| p.respond_to?(:table_name_prefix) } || self).table_name_prefix + end + # 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 |