diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-16 11:46:34 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-16 13:52:07 +0000 |
commit | 0b08ff7d92124cc370e9f0795d1559204f04f9a4 (patch) | |
tree | 3f7e8a98b782952e12d872f20cb7603d1b014d13 /activerecord/lib/active_record/model_schema.rb | |
parent | 4fe76f4f272571bb88aa54af1d7e6bcad413c6e1 (diff) | |
download | rails-0b08ff7d92124cc370e9f0795d1559204f04f9a4.tar.gz rails-0b08ff7d92124cc370e9f0795d1559204f04f9a4.tar.bz2 rails-0b08ff7d92124cc370e9f0795d1559204f04f9a4.zip |
Cache columns at the model level.
Allows two models to use the same table but have different primary keys.
Diffstat (limited to 'activerecord/lib/active_record/model_schema.rb')
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 058161a2cb..9ed871a1cb 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -221,16 +221,16 @@ module ActiveRecord # Returns an array of column objects for the table associated with this class. def columns - if defined?(@primary_key) - connection.schema_cache.primary_keys[table_name] ||= primary_key + @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 - connection.schema_cache.columns_hash[table_name] + @columns_hash ||= Hash[columns.map { |c| [c.name, c] }] end # Returns a hash where the keys are column names and the values are @@ -295,7 +295,8 @@ module ActiveRecord undefine_attribute_methods connection.schema_cache.clear_table_cache!(table_name) if table_exists? - @column_names = @content_columns = @column_defaults = @dynamic_methods_hash = @inheritance_column = nil + @column_names = @content_columns = @column_defaults = @columns = @columns_hash = nil + @dynamic_methods_hash = @inheritance_column = nil @arel_engine = @relation = nil end |