Q:

How to chain where conditions with "or" in Rails 4?

In my Rails 4 app I need to find all plans that do either have an interval of month OR an amount of 0.
This doesn't work:
class Plan < ActiveRecord::Base

  def self.by_interval(interval)
    where("interval = ? OR amount = ?", interval, 0)
  end

end

I am getting this error:
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 '= 'month' OR amount = 0)  ORDER BY amount DESC' at line 1: SELECT `plans`.* FROM `plans`  WHERE (interval = 'month' OR amount = 0)  ORDER BY amount DESC

What else might work?
Thanks for any help.

A:

'interval' in mysql is a reserved word (http://dev.mysql.com/doc/refman/5.6/en/reserved-words.html).
Try it like this:
def self.by_interval(interval)
  where("`interval` = ? OR amount = ?", interval, 0)
end

note the backticks around "interval" (not quotes)

