Permalink
Browse files

Defaults hash can go on the model

  • Loading branch information...
1 parent 0b08ff7 commit dee94d8ab5b7d27653052441a3b408db380dd784 @jonleighton jonleighton committed Dec 16, 2011
View
15 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 @@ def initialize(conn)
}]
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,23 +31,17 @@ def table_exists?(name)
@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
# Clear out internal caches for table with +table_name+.
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
View
2 activerecord/lib/active_record/model_schema.rb
@@ -236,7 +236,7 @@ def columns_hash
# 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.

0 comments on commit dee94d8

Please sign in to comment.