diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-28 15:38:16 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-28 18:27:41 +0000 |
commit | 93c1f11c0a5097a5431819a1551a02a869a16a38 (patch) | |
tree | fd88de442e03a600df63387dc4b2389e9c861c7b /activerecord/lib/active_record/model_schema.rb | |
parent | afe6e059ea216f01d160e4603116356b78df12e5 (diff) | |
download | rails-93c1f11c0a5097a5431819a1551a02a869a16a38.tar.gz rails-93c1f11c0a5097a5431819a1551a02a869a16a38.tar.bz2 rails-93c1f11c0a5097a5431819a1551a02a869a16a38.zip |
Support configuration on ActiveRecord::Model.
The problem: We need to be able to specify configuration in a way that
can be inherited to models that include ActiveRecord::Model. So it is
no longer sufficient to put 'top level' config on ActiveRecord::Base,
but we do want configuration specified on ActiveRecord::Base and
descendants to continue to work.
So we need something like class_attribute that can be defined on a
module but that is inherited when ActiveRecord::Model is included.
The solution: added ActiveModel::Configuration module which provides a
config_attribute macro. It's a bit specific hence I am not putting this
in Active Support or making it a 'public API' at present.
Diffstat (limited to 'activerecord/lib/active_record/model_schema.rb')
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index adf85c6436..d9d18a9752 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -5,18 +5,18 @@ module ActiveRecord module ModelSchema extend ActiveSupport::Concern - ## - # :singleton-method: - # Accessor for the prefix type that will be prepended to every primary key column name. - # The options are :table_name and :table_name_with_underscore. If the first is specified, - # the Product class will look for "productid" instead of "id" as the primary column. If the - # latter is specified, the Product class will look for "product_id" instead of "id". Remember - # that this is a global setting for all Active Records. - Configuration.define :primary_key_prefix_type - included do ## # :singleton-method: + # Accessor for the prefix type that will be prepended to every primary key column name. + # The options are :table_name and :table_name_with_underscore. If the first is specified, + # the Product class will look for "productid" instead of "id" as the primary column. If the + # latter is specified, the Product class will look for "product_id" instead of "id". Remember + # that this is a global setting for all Active Records. + config_attribute :primary_key_prefix_type, :global => true + + ## + # :singleton-method: # 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. @@ -25,14 +25,14 @@ module ActiveRecord # 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. - class_attribute :table_name_prefix, :instance_writer => false + config_attribute :table_name_prefix self.table_name_prefix = "" ## # :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. - class_attribute :table_name_suffix, :instance_writer => false + config_attribute :table_name_suffix self.table_name_suffix = "" ## @@ -40,7 +40,7 @@ module ActiveRecord # Indicates whether table names should be the pluralized versions of the corresponding class names. # If true, the default table name for a Product class will be +products+. If false, it would just be +product+. # See table_name for the full rules on table/class naming. This is true, by default. - class_attribute :pluralize_table_names, :instance_writer => false + config_attribute :pluralize_table_names self.pluralize_table_names = true end |