aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-23 10:59:30 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-23 11:09:48 -0700
commit05dd3df35db8b2d39ed177f4ccfe112bdfe7726d (patch)
treee4956819b7267254015ccbb367307e527231dff5 /activerecord/lib
parentb318758bda9f9ea9c94abb81e8a66a8b48cb720c (diff)
downloadrails-05dd3df35db8b2d39ed177f4ccfe112bdfe7726d.tar.gz
rails-05dd3df35db8b2d39ed177f4ccfe112bdfe7726d.tar.bz2
rails-05dd3df35db8b2d39ed177f4ccfe112bdfe7726d.zip
Remove `Column#primary`
It appears to have been used at some point in the past, but is no longer used in any meaningful way. Whether a column is considered primary is a property of the model, not the schema/column. This also removes the need for yet another layer of caching of the model's schema, and we can leave that to the schema cache.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb3
-rw-r--r--activerecord/lib/active_record/model_schema.rb12
3 files changed, 5 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 8bd51dc71f..d44aebec39 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -455,7 +455,7 @@ module ActiveRecord
end
def pk_attribute?(name)
- column_for_attribute(name).primary
+ name == self.class.primary_key
end
def typecasted_attribute_value(name)
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 704868c058..42aabd6d7f 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -14,7 +14,7 @@ module ActiveRecord
end
attr_reader :name, :default, :cast_type, :null, :sql_type, :default_function
- attr_accessor :primary, :coder
+ attr_accessor :coder
alias :encoded? :coder
@@ -36,7 +36,6 @@ module ActiveRecord
@null = null
@default = extract_default(default)
@default_function = nil
- @primary = nil
@coder = nil
end
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index aa1166750f..8449fb1266 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -219,16 +219,12 @@ module ActiveRecord
# Returns an array of column objects for the table associated with this class.
def columns
- @columns ||= connection.schema_cache.columns(table_name).map do |col|
- col = col.dup
- col.primary = (col.name == primary_key)
- col
- end
+ connection.schema_cache.columns(table_name)
end
# Returns a hash of column objects for the table associated with this class.
def columns_hash
- @columns_hash ||= Hash[columns.map { |c| [c.name, c] }]
+ connection.schema_cache.columns_hash(table_name)
end
def column_types # :nodoc:
@@ -271,7 +267,7 @@ module ActiveRecord
# Returns an array of column objects where the primary id, all columns ending in "_id" or "_count",
# and columns used for single table inheritance have been removed.
def content_columns
- @content_columns ||= columns.reject { |c| c.primary || c.name =~ /(_id|_count)$/ || c.name == inheritance_column }
+ @content_columns ||= columns.reject { |c| c.name == primary_key || c.name =~ /(_id|_count)$/ || c.name == inheritance_column }
end
# Resets all the cached information about columns, which will cause them
@@ -308,8 +304,6 @@ module ActiveRecord
@arel_engine = nil
@column_defaults = nil
@column_names = nil
- @columns = nil
- @columns_hash = nil
@column_types = nil
@content_columns = nil
@dynamic_methods_hash = nil