views:

26

answers:

1

So in rails I use sqlite3 for development and mysql for production. Sqlite3 and mysql handle booleans differently ("t" or "f" in sqlite3 and true or false on mysql). Usually it's not a problem when I do a find because I can do this:

Comment.find(:all, :conditions => ["viewed = ?", false])

And rails will insert the appropriate value depending on environment. But what if I want to do a find_by_sql in which I need a boolean?

+3  A: 

You're in luck! #find_by_sql also performs database-agnostic string replacement when you pass it an array.

Comment.find_by_sql(["SELECT * FROM comments WHERE viewed = ?",  false])
Raphomet
ahhhh... I'm retarded, I guess I should have just tried that before posting this question.
tybro0103