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 wrong?
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 wrong?
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.