If you send boolean's true to the integer column, it will be treated as one of the integers, so is there a way to set it to be treated as boolean in bulk?

Asked 2 months ago, Updated 2 months ago, 1 views

It's just as the title says.I understand that if you use before_type_cast, it will be a workaround, but there are many changes, so I would appreciate it if you could apply them in one place, such as config.
By the way, I wonder if I can see the background of this specification (such as github's MR and issue).
I'm curious why it's designed like this.


#request json

  "user_name": "test",

400 Error

201 Created

#response json

  "user_name": "test",

Rails version:5.0.1

Ruby version: 2.3.1


2022-09-30 11:08

1 Answers

mysql>select true from dual;
|    1 |
1 row in set (0.00 sec)

If you are using mysql, then true and 1 are equivalent in the database as shown above.

If you want to start true, I think it is necessary to determine whether the parameters received by the controller are numeric strings.For example,


and so on.

2022-09-30 11:08

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.