Mysql2::Error: You have an error in your SQL synta

2019-08-05 04:42发布

I just used this to switch my rails app db from sqlite3 to mysql2 and that seemed to work out properly.

But when I start up my app I'm now getting this:

A ActionView::Template::Error occurred in pages#dashboard:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== 1) LIMIT 20 OFFSET 0' at line 1: SELECT `tickets`.* FROM `tickets` WHERE (archived == 1) LIMIT 20 OFFSET 0
activerecord (3.0.3) lib/active_record/connection_adapters/abstract_adapter.rb:202:in `log'

Not sure where to look to get this working properly. Any help would be appreciated. Thanks!

1条回答
萌系小妹纸
2楼-- · 2019-08-05 05:15

Try this:

# Notice single = vs ==
WHERE (archived = 1)

Update Ended up doing

scope :is_archived, where('archived != ?', 1)
scope :not_archived, where('archived = ?', 1)

This worked great. Thanks!

查看更多
登录 后发表回答