diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-29 10:56:33 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-29 10:56:33 -0700 |
commit | 295e91221123b912f2545cdc2e5623aeb53b220f (patch) | |
tree | a41a2591753ceb1c3bb2c242a3461d7fc9a5c75a /activerecord/lib | |
parent | 8ed1a562c6293c81c894f3fe55fe88610c4f6caa (diff) | |
parent | 4584be9b8bd15277cc05e8729830247df45d46dc (diff) | |
download | rails-295e91221123b912f2545cdc2e5623aeb53b220f.tar.gz rails-295e91221123b912f2545cdc2e5623aeb53b220f.tar.bz2 rails-295e91221123b912f2545cdc2e5623aeb53b220f.zip |
Merge branch 'master' into mapper
* master:
Update url to rake docs [ci skip]
Name#model_name doesn't return a String object
Result sets never override a model's column type
[ci skip] Make last note show up in postgresql guide.
Add missing `:param` option from the docs for Mapper#match [ci skip] Option discovered by @zackperdue in #14741, implemented in #5581.
Add @senny's changed from #14741, including code font for `resources` options, and wrapped to 80 chars. [ci skip]
Use github url for homepage of log4r [ci skip]
Remove TODO.
Ensure we always use instances of the adapter specific column class
Fix indentation from 1b4b26f [ci skip]
[ci skip] Improve form_helpers.md guide.
Clear inflections after test.
Remove unnecessary include for integration tests.
Added documentation for the :param option for resourceful routing
Diffstat (limited to 'activerecord/lib')
6 files changed, 16 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index a8e0cb93a0..b589cfee09 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -363,6 +363,10 @@ module ActiveRecord end end + def new_column(name, default, cast_type, sql_type = nil, null = true) + Column.new(name, default, cast_type, sql_type, null) + end + protected def lookup_cast_type(sql_type) # :nodoc: diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 82e62786ca..2677b6ee83 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -206,8 +206,7 @@ module ActiveRecord raise NotImplementedError end - def new_column(field, default, sql_type, null, collation, extra = "") # :nodoc: - cast_type = lookup_cast_type(sql_type) + def new_column(field, default, cast_type, sql_type = nil, null = true, collation = "", extra = "") # :nodoc: Column.new(field, default, cast_type, sql_type, null, collation, strict_mode?, extra) end @@ -425,7 +424,9 @@ module ActiveRecord execute_and_free(sql, 'SCHEMA') do |result| each_hash(result).map do |field| field_name = set_field_encoding(field[:Field]) - new_column(field_name, field[:Default], field[:Type], field[:Null] == "YES", field[:Collation], field[:Extra]) + sql_type = field[:Type] + cast_type = lookup_cast_type(sql_type) + new_column(field_name, field[:Default], cast_type, sql_type, field[:Null] == "YES", field[:Collation], field[:Extra]) end end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 484c44dc8d..b4d53eba26 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -181,10 +181,14 @@ module ActiveRecord oid = get_oid_type(oid.to_i, fmod.to_i, column_name, type) default_value = extract_value_from_default(default) default_function = extract_default_function(default_value, default) - PostgreSQLColumn.new(column_name, default_value, oid, type, notnull == 'f', default_function) + new_column(column_name, default_value, oid, type, notnull == 'f', default_function) end end + def new_column(name, default, cast_type, sql_type = nil, null = true, default_function = nil) # :nodoc: + PostgreSQLColumn.new(name, default, cast_type, sql_type, null, default_function) + end + # Returns the current database name. def current_database query('select current_database()', 'SCHEMA')[0][0] diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index a5e2619cb8..adf893d7e7 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -393,7 +393,7 @@ module ActiveRecord sql_type = field['type'] cast_type = lookup_cast_type(sql_type) - Column.new(field['name'], field['dflt_value'], cast_type, sql_type, field['notnull'].to_i == 0) + new_column(field['name'], field['dflt_value'], cast_type, sql_type, field['notnull'].to_i == 0) end end diff --git a/activerecord/lib/active_record/properties.rb b/activerecord/lib/active_record/properties.rb index c99594c823..cc1e8b45c1 100644 --- a/activerecord/lib/active_record/properties.rb +++ b/activerecord/lib/active_record/properties.rb @@ -65,7 +65,7 @@ module ActiveRecord def property(name, cast_type) name = name.to_s # Assign a new hash to ensure that subclasses do not share a hash - self.user_provided_columns = user_provided_columns.merge(name => ConnectionAdapters::Column.new(name, nil, cast_type)) + self.user_provided_columns = user_provided_columns.merge(name => connection.new_column(name, nil, cast_type)) end # Returns an array of column objects for the table associated with this class. diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb index ef138c6f80..1fe54cea3f 100644 --- a/activerecord/lib/active_record/querying.rb +++ b/activerecord/lib/active_record/querying.rb @@ -40,7 +40,7 @@ module ActiveRecord column_types = {} if result_set.respond_to? :column_types - column_types = result_set.column_types + column_types = result_set.column_types.merge(columns_hash) else ActiveSupport::Deprecation.warn "the object returned from `select_all` must respond to `column_types`" end |