diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-10-19 15:08:58 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-10-19 15:08:58 +0100 |
commit | af8c8b432abfe478f478fee35c5624c8c04d65e4 (patch) | |
tree | 180b195f1d2d8b899a5f993ffe531b45ffaf5a29 /activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | |
parent | eb72e62c3042c0df989d951b1d12291395ebdb8e (diff) | |
download | rails-af8c8b432abfe478f478fee35c5624c8c04d65e4.tar.gz rails-af8c8b432abfe478f478fee35c5624c8c04d65e4.tar.bz2 rails-af8c8b432abfe478f478fee35c5624c8c04d65e4.zip |
The default value of a text/blob in mysql strict mode should be nil
In non-strict mode it is '', but if someone is in strict mode then we
should honour the strict semantics.
Also, this removes the need for a completely horrible hack in dirty.rb.
Closes #7780
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 18 |
1 files changed, 10 insertions, 8 deletions
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 8c83c4f5db..b0e7bd7e82 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -4,17 +4,19 @@ module ActiveRecord module ConnectionAdapters class AbstractMysqlAdapter < AbstractAdapter class Column < ConnectionAdapters::Column # :nodoc: - attr_reader :collation + attr_reader :collation, :strict - def initialize(name, default, sql_type = nil, null = true, collation = nil) - super(name, default, sql_type, null) + def initialize(name, default, sql_type = nil, null = true, collation = nil, strict = false) + @strict = strict @collation = collation + + super(name, default, sql_type, null) end def extract_default(default) if sql_type =~ /blob/i || type == :text if default.blank? - return null ? nil : '' + null || strict ? nil : '' else raise ArgumentError, "#{type} columns cannot have a default value: #{default.inspect}" end @@ -30,10 +32,6 @@ module ActiveRecord super end - def explicit_default? - !null && (sql_type =~ /blob/i || type == :text) - end - # Must return the relevant concrete adapter def adapter raise NotImplementedError @@ -571,6 +569,10 @@ module ActiveRecord where_sql end + def strict_mode? + @config.fetch(:strict, true) + end + protected # MySQL is too stupid to create a temporary table for use subquery, so we have |