Skip to content
Browse files

Unifies mysql and mysql2 casting of booleans.

  • Loading branch information...
1 parent 07790d5 commit 07ae1e9b5557182f69e5ffbac54b334284abf36f @senny senny committed Aug 7, 2013
View
7 activerecord/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Unify boolean type casting for `MysqlAdapter` and `Mysql2Adapter`.
+ `type_cast` will return `1` for `true` and `0` for `false`.
+
+ Fixes #11119.
+
+ *Adam Williams*, *Yves Senn*
+
* Fix bug where has_one associaton record update result in crash, when replaced with itself.
Fixes #12834.
View
6 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -206,6 +206,12 @@ def supports_index_sort_order?
true
end
+ def type_cast(value, column)
+ return super unless value == true || value == false
+
+ value ? 1 : 0
+ end
+
# MySQL 4 technically support transaction isolation, but it is affected by a bug
# where the transaction level gets persisted for the whole session:
#
View
6 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -160,12 +160,6 @@ def error_number(exception) # :nodoc:
# QUOTING ==================================================
- def type_cast(value, column)
- return super unless value == true || value == false
-
- value ? 1 : 0
- end
-
def quote_string(string) #:nodoc:
@connection.quote(string)
end
View
6 activerecord/test/cases/adapters/mysql2/boolean_test.rb
@@ -46,8 +46,8 @@ class BooleanType < ActiveRecord::Base
assert_equal 1, attributes["archived"]
assert_equal "1", attributes["published"]
- assert_equal "t", @connection.type_cast(true, boolean_column)
- assert_equal "t", @connection.type_cast(true, string_column)
+ assert_equal 1, @connection.type_cast(true, boolean_column)
+ assert_equal 1, @connection.type_cast(true, string_column)
end
test "test type casting without emulated booleans" do
@@ -60,7 +60,7 @@ class BooleanType < ActiveRecord::Base
assert_equal "1", attributes["published"]
assert_equal 1, @connection.type_cast(true, boolean_column)
- assert_equal "t", @connection.type_cast(true, string_column)
+ assert_equal 1, @connection.type_cast(true, string_column)
end
test "with booleans stored as 1 and 0" do

0 comments on commit 07ae1e9

Please sign in to comment.
Something went wrong with that request. Please try again.