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
+
1
8
* Fix bug where has_one associaton record update result in crash, when replaced with itself.
2
9
3
10
Fixes #12834 .
Original file line number Diff line number Diff line change @@ -206,6 +206,12 @@ def supports_index_sort_order?
206
206
true
207
207
end
208
208
209
+ def type_cast ( value , column )
210
+ return super unless value == true || value == false
211
+
212
+ value ? 1 : 0
213
+ end
214
+
209
215
# MySQL 4 technically support transaction isolation, but it is affected by a bug
210
216
# where the transaction level gets persisted for the whole session:
211
217
#
Original file line number Diff line number Diff line change @@ -160,12 +160,6 @@ def error_number(exception) # :nodoc:
160
160
161
161
# QUOTING ==================================================
162
162
163
- def type_cast ( value , column )
164
- return super unless value == true || value == false
165
-
166
- value ? 1 : 0
167
- end
168
-
169
163
def quote_string ( string ) #:nodoc:
170
164
@connection . quote ( string )
171
165
end
Original file line number Diff line number Diff line change @@ -46,8 +46,8 @@ class BooleanType < ActiveRecord::Base
46
46
assert_equal 1 , attributes [ "archived" ]
47
47
assert_equal "1" , attributes [ "published" ]
48
48
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 )
51
51
end
52
52
53
53
test "test type casting without emulated booleans" do
@@ -60,7 +60,7 @@ class BooleanType < ActiveRecord::Base
60
60
assert_equal "1" , attributes [ "published" ]
61
61
62
62
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 )
64
64
end
65
65
66
66
test "with booleans stored as 1 and 0" do
You can’t perform that action at this time.
0 commit comments