aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-16 12:00:25 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-16 13:52:07 +0000
commitdee94d8ab5b7d27653052441a3b408db380dd784 (patch)
treeb2fdf5fef7310b10ec8def15f2130d44e60edc56 /activerecord
parent0b08ff7d92124cc370e9f0795d1559204f04f9a4 (diff)
downloadrails-dee94d8ab5b7d27653052441a3b408db380dd784.tar.gz
rails-dee94d8ab5b7d27653052441a3b408db380dd784.tar.bz2
rails-dee94d8ab5b7d27653052441a3b408db380dd784.zip
Defaults hash can go on the model
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/schema_cache.rb15
-rw-r--r--activerecord/lib/active_record/model_schema.rb2
2 files changed, 2 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
index 447e309f23..a8f7fd3648 100644
--- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
@@ -2,7 +2,6 @@ module ActiveRecord
module ConnectionAdapters
class SchemaCache
attr_reader :columns, :columns_hash, :primary_keys, :tables
- attr_reader :column_defaults
attr_reader :connection
def initialize(conn)
@@ -19,12 +18,6 @@ module ActiveRecord
}]
end
- @column_defaults = Hash.new do |h, table_name|
- h[table_name] = Hash[columns[table_name].map { |col|
- [col.name, col.default]
- }]
- end
-
@primary_keys = Hash.new do |h, table_name|
h[table_name] = table_exists?(table_name) ?
conn.primary_key(table_name) : 'id'
@@ -38,15 +31,10 @@ module ActiveRecord
@tables[name] = connection.table_exists?(name)
end
- # Clears out internal caches:
- #
- # * columns
- # * columns_hash
- # * tables
+ # Clears out internal caches
def clear!
@columns.clear
@columns_hash.clear
- @column_defaults.clear
@tables.clear
end
@@ -54,7 +42,6 @@ module ActiveRecord
def clear_table_cache!(table_name)
@columns.delete table_name
@columns_hash.delete table_name
- @column_defaults.delete table_name
@primary_keys.delete table_name
@tables.delete table_name
end
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index 9ed871a1cb..36417d89f7 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -236,7 +236,7 @@ module ActiveRecord
# Returns a hash where the keys are column names and the values are
# default values when instantiating the AR object for this table.
def column_defaults
- @column_defaults ||= connection.schema_cache.column_defaults[table_name]
+ @column_defaults ||= Hash[columns.map { |c| [c.name, c.default] }]
end
# Returns an array of column names as strings.