I have a Lesson model that has an order field of type integer. What i want to do is find the previous lesson.
Lesson.where("order < ?" , 8)
This causes the following error. Any help would be appreciated.
Lesson Load (1.9ms) SELECT "lessons".* FROM "lessons" WHERE (order < 8) LIMIT $1 [["LIMIT", 11]]
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "order"
LINE 1: SELECT "lessons".* FROM "lessons" WHERE (order < 8) LIMIT...
: SELECT "lessons".* FROM "lessons" WHERE (order < 8) LIMIT $1
That would make sense since you use ORDER to sort in SQL.
I guess you could modify the code to be the following to specify the column and clarify it for the db that you're not using the ORDER keyword.
Lesson.where("lessons.order < ?" , 8)
I'd much rather rename the column though.
Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.