File tree Expand file tree Collapse file tree 4 files changed +16
-9
lines changed
lib/active_record/connection_adapters
test/cases/adapters/mysql2 Expand file tree Collapse file tree 4 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1+ * Unify boolean type casting for ` MysqlAdapter ` and ` Mysql2Adapter ` .
2+ ` type_cast ` will return ` 1 ` for ` true ` and ` 0 ` for ` false ` .
3+
4+ Fixes #11119 .
5+
6+ * Adam Williams* , * Yves Senn*
7+
18* Fix bug where has_one associaton record update result in crash, when replaced with itself.
29
310 Fixes #12834 .
Original file line number Diff line number Diff line change @@ -206,6 +206,12 @@ def supports_index_sort_order?
206206 true
207207 end
208208
209+ def type_cast ( value , column )
210+ return super unless value == true || value == false
211+
212+ value ? 1 : 0
213+ end
214+
209215 # MySQL 4 technically support transaction isolation, but it is affected by a bug
210216 # where the transaction level gets persisted for the whole session:
211217 #
Original file line number Diff line number Diff line change @@ -160,12 +160,6 @@ def error_number(exception) # :nodoc:
160160
161161 # QUOTING ==================================================
162162
163- def type_cast ( value , column )
164- return super unless value == true || value == false
165-
166- value ? 1 : 0
167- end
168-
169163 def quote_string ( string ) #:nodoc:
170164 @connection . quote ( string )
171165 end
Original file line number Diff line number Diff line change @@ -46,8 +46,8 @@ class BooleanType < ActiveRecord::Base
4646 assert_equal 1 , attributes [ "archived" ]
4747 assert_equal "1" , attributes [ "published" ]
4848
49- assert_equal "t" , @connection . type_cast ( true , boolean_column )
50- assert_equal "t" , @connection . type_cast ( true , string_column )
49+ assert_equal 1 , @connection . type_cast ( true , boolean_column )
50+ assert_equal 1 , @connection . type_cast ( true , string_column )
5151 end
5252
5353 test "test type casting without emulated booleans" do
@@ -60,7 +60,7 @@ class BooleanType < ActiveRecord::Base
6060 assert_equal "1" , attributes [ "published" ]
6161
6262 assert_equal 1 , @connection . type_cast ( true , boolean_column )
63- assert_equal "t" , @connection . type_cast ( true , string_column )
63+ assert_equal 1 , @connection . type_cast ( true , string_column )
6464 end
6565
6666 test "with booleans stored as 1 and 0" do
You can’t perform that action at this time.
0 commit comments