I'm trying to find all messages where the .user field is either of two values.
.user is a string
@msgs = Foo.find :all,
:order => 'created_at ASC',
开发者_开发知识库 :conditions => [ "(user = ?) OR (user = ?)", @user1, @user2]
this query, on heroku (postgres) always returns empty
running locally, it returns data as expected.
Why does this not work? I'm absolutely positive the values in @user1 and @user2 do match data in the .user field because when I remove the conditions then filter in the VIEW using those same variable names it works fine.
the problem is postgres apparently does not like having a field named 'user' when I changed the fieldname it worked perfectly.
Perhaps case sensitivity is the issue? I believe postgres is case-sensitive by default.
Try
:conditions => [ "UPPER(user) = UPPER(?) OR UPPER(user) = UPPER(?)", @user1, @user2]
精彩评论