diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-10-20 20:21:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-20 20:21:50 +0900 |
commit | 05ceec4ea430bae4acfbf18f7c29d10875fbc9f0 (patch) | |
tree | dc3494fcfabaf49a4dc128de40cbb2f16e4d2469 /activerecord/lib/active_record | |
parent | 158f67d94c027c7f4516b000f90ec10c1335a86c (diff) | |
parent | e9f82e76e83497db094fe63104f548453fbe512e (diff) | |
download | rails-05ceec4ea430bae4acfbf18f7c29d10875fbc9f0.tar.gz rails-05ceec4ea430bae4acfbf18f7c29d10875fbc9f0.tar.bz2 rails-05ceec4ea430bae4acfbf18f7c29d10875fbc9f0.zip |
Merge pull request #30928 from Altech/indifferent-ignored-columns
Allow symbol list for ignored_columns
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 34c0ef4e75..bed9400f51 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -115,20 +115,6 @@ module ActiveRecord # 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. - ## - # :singleton-method: ignored_columns - # :call-seq: ignored_columns - # - # The list of columns names the model should ignore. Ignored columns won't have attribute - # accessors defined, and won't be referenced in SQL queries. - - ## - # :singleton-method: ignored_columns= - # :call-seq: ignored_columns=(columns) - # - # Sets the columns names the model should ignore. Ignored columns won't have attribute - # accessors defined, and won't be referenced in SQL queries. - included do mattr_accessor :primary_key_prefix_type, instance_writer: false @@ -138,9 +124,9 @@ module ActiveRecord class_attribute :internal_metadata_table_name, instance_accessor: false, default: "ar_internal_metadata" class_attribute :protected_environments, instance_accessor: false, default: [ "production" ] class_attribute :pluralize_table_names, instance_writer: false, default: true - class_attribute :ignored_columns, instance_accessor: false, default: [].freeze self.inheritance_column = "type" + self.ignored_columns = [].freeze delegate :type_for_attribute, to: :class @@ -271,6 +257,22 @@ module ActiveRecord @explicit_inheritance_column = true end + # The list of columns names the model should ignore. Ignored columns won't have attribute + # accessors defined, and won't be referenced in SQL queries. + def ignored_columns + if defined?(@ignored_columns) + @ignored_columns + else + superclass.ignored_columns + end + end + + # Sets the columns names the model should ignore. Ignored columns won't have attribute + # accessors defined, and won't be referenced in SQL queries. + def ignored_columns=(columns) + @ignored_columns = columns.map(&:to_s) + end + def sequence_name if base_class == self @sequence_name ||= reset_sequence_name |