开发者

Why is Model.scoped generating invalid SQL?

开发者 https://www.devze.com 2022-12-31 18:30 出处:网络
When I run Book.scoped({:conditions => [\'books.index LIKE ?\',\'%query%\']}) I get: ActiveRecord::StatementInvalid: SQLite3::SQLException: near \"index\": syntax error: SELECT * FROM \"books\" WH

When I run Book.scoped({:conditions => ['books.index LIKE ?','%query%']}) I get:

ActiveRecord::StatementInvalid: SQLite3::SQLException: near "index": syntax error: SELECT * FROM "books" WHERE (books.index like '%query%')

What am I doing wro开发者_C百科ng?


Credit goes to Adam Bernier for pointing out that index is a SQL keyword (cf. comment on question). I am reposting the solution here so that this question gets marked as answered.

While

Book.scoped({:conditions => ['`index` LIKE ?','%query%']})

works, for peace of mind, I decided to rename the column.

0

精彩评论

暂无评论...
验证码 换一张
取 消