2010-05-18 43 views
1

當我運行Book.scoped({:conditions => ['books.index LIKE ?','%query%']})我得到:爲什麼Model.scoped生成無效的SQL?

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

我在做什麼錯?

+0

INDEX是SQL中的關鍵字。在原始SQL中,你會雙引號:「INDEX」;不知道除了重命名列之外,你會如何修復Rails。祝你好運。 – bernie 2010-05-18 22:28:48

回答

2

對於指出index是SQL關鍵字(參見問題評論),請參閱Adam Bernier。我在此處重新發布解決方案,以便將此問題標記爲已回答。

雖然

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

作品,安心,我決定重新命名列。