My code runs fine for sqllite locally, but when I push to heroku I get:
ActiveRecord::StatementInvalid (PGError: ERROR: syntax error at or near "NULL"
LINE 1: ...LECT "beeps".* FROM "beeps" WHERE ((widget_id NOT NULL) AND ...
^
: SELECT "beeps".* FROM "beeps" WHERE ((widget_id NOT NULL) AND (updated_at > '2011-02-06 02:27:59.867809') AND (userphone = '0000000xxxx') AND (beeper
= '0000000zzzz') AND (inbound = 't')) ORDER BY beeps.id DESC LIMIT 1):
the ruby code is :
Beep.last(:conditions => [ "(widget_id NOT NULL) AND (updated_at > ?) AND (userphone = ?) AND (beeper = ?) AND (inbound = ?)", 5.minutes.ago, aphone, beeper, inboundflag ])
By the way, is there any way to structure this query using pure active record, so we can (hopefully) avoid database-specific query strings?
Are you sure you are using SQLLite on Heroku and not MySQL? Either way the query syntax seems a little incorrect. I would modify your query to this:
If you are using Rails3 you can chain your conditions together like this:
Beep.where('widget_id IS NOT NULL) .where('updated_at > ?', 5.minutes.ago) .where(userphone: aphone) .where(beeper: beeper) .where(inbound: inboundflag) .last