diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-06-12 06:56:51 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-06-12 06:56:51 +0000 |
commit | d0bd3b5af4a796d8f0b83815a3f164ae811c0626 (patch) | |
tree | 02ebe7f6eeab523dcf5190845b95a9b91ed1affb /activerecord/lib/active_record/base.rb | |
parent | 3cb26e9cb3c1f3a069e7654988c650ca12322ede (diff) | |
download | rails-d0bd3b5af4a796d8f0b83815a3f164ae811c0626.tar.gz rails-d0bd3b5af4a796d8f0b83815a3f164ae811c0626.tar.bz2 rails-d0bd3b5af4a796d8f0b83815a3f164ae811c0626.zip |
Return PostgreSQL columns in the order they are declared #1374 (perlguy@gmail.com). Unit test column order, adapter housekeeping, simplify users of columns_hash.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1405 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 49d6a0c7d6..0a953cfcd0 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -617,9 +617,9 @@ module ActiveRecord #:nodoc: def columns_hash @columns_hash ||= columns.inject({}) { |hash, column| hash[column.name] = column; hash } end - + def column_names - @column_names ||= columns_hash.keys + @column_names ||= columns.map { |column| column.name } end # Returns an array of columns objects where the primary id, all columns ending in "_id" or "_count", @@ -632,7 +632,7 @@ module ActiveRecord #:nodoc: # and true as the value. This makes it possible to do O(1) lookups in respond_to? to check if a given method for attribute # is available. def column_methods_hash - @dynamic_methods_hash ||= columns_hash.keys.inject(Hash.new(false)) do |methods, attr| + @dynamic_methods_hash ||= column_names.inject(Hash.new(false)) do |methods, attr| methods[attr.to_sym] = true methods["#{attr}=".to_sym] = true methods["#{attr}?".to_sym] = true @@ -1293,16 +1293,14 @@ module ActiveRecord #:nodoc: # Returns copy of the attributes hash where all the values have been safely quoted for use in # an SQL statement. def attributes_with_quotes(include_primary_key = true) - columns_hash = self.class.columns_hash - - attrs_quoted = attributes.inject({}) do |attrs_quoted, pair| - attrs_quoted[pair.first] = quote(pair.last, columns_hash[pair.first]) unless !include_primary_key && pair.first == self.class.primary_key - attrs_quoted + attributes.inject({}) do |quoted, (name, value)| + if column = column_for_attribute(name) + quoted[name] = quote(value, column) unless !include_primary_key && name == self.class.primary_key + end + quoted end - - attrs_quoted.delete_if { |key, value| !self.class.columns_hash.keys.include?(key) } end - + # Quote strings appropriately for SQL statements. def quote(value, column = nil) connection.quote(value, column) |