开发者

Why is Model.scoped generating invalid SQL?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜