开发者

rails 3, on heroku, how query for either of 2 different values in one field?

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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜