导轨 - 如何搜索基于布尔型字段? (MySQL错误) [英] Rails - how to search based on a boolean field? (MySQL error)
本文介绍了导轨 - 如何搜索基于布尔型字段? (MySQL错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我运行下面的查询
@projects = @company.projects.where("active = ?", true).order("created_at ASC")
和我收到的错误:
`ActiveRecord::StatementInvalid: Mysql::ParseError: You have an error in your SQL...`
错误指向 ='1'
。
我试过在我的查询许多变化,但我不能找出问题。我该如何解决这个问题?
I've tried many variations on my query but I cannot figure out the problem. How can I solve this?
推荐答案
您不需要使用参数化查询与文字,只是这样做:
You don't need to use parameterized queries with literals, just do this:
@projects = @company.projects.where("active = 1").order("created_at ASC")
这篇关于导轨 - 如何搜索基于布尔型字段? (MySQL错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文