During an upgrade of rails
version in my application from 4.1.8
to 4.2.0
, I have encountered the following issue.
String literals in where
conditions are now additionally wrapped into quotation marks, which then become part of a query string, delivering no valid results anymore. This happens only for database fields of a text
type ( varchar
fields are not affected). I am using a MySQL database.
> Table.where(column: 'data')
[08:19:20.822552] Table Load (0.3ms) SELECT `table`.* FROM `table`
WHERE `table`.`column` = '\"data\"'
Now, if you have a row containing data
value in a column row, this condition will no longer match (obviously, "data"
is not a match anymore).
In Rails 4.1.8 everything worked perfectly fine:
> Table.where(column: 'data')
[08:19:58.303366] Table Load (0.4ms) SELECT `table`.* FROM `table`
WHERE `table`.`column` = 'data'
I don't know if this is a default or a configurable behaviour. I somehow haven't found a corresponding release note on that. I would be very grateful for any suggestions on what has changed and what is the best way to fix it.
Many thanks for help!
Could you try this way:
Table.where("column=?", 'data')
I guess this will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.