我有张叫的桌子
inbox_messages
包含以下行:
user_id message_id
======= ==========
4 8
4 1
4 7
0 9
0 10
0 11
0 12
该表映射到以下模型:
class InboxMessage < ActiveRecord::Base
end
当我调用
find
方法与A
IN
Caluse,我会根据位置得到不同的结果集
参数。
InboxMessage.find(:all, :conditions => [ "user_id IN (?)", "0,4"]) # 8 rows
InboxMessage.find(:all, :conditions => [ "user_id IN (?)", "4,0"]) # 3 rows
上面的第二个调用,返回3行而不是8行。其他情况也可以,即
InboxMessage.find(:all, :conditions => [ "user_id IN (0, 4)" ]) # 8 rows
InboxMessage.find(:all, :conditions => [ "user_id IN (4, 0)" ]) # 8 rows
InboxMessage.find(:all, :conditions => [ :user_id => [0, 4] ]) # 8 rows
InboxMessage.find(:all, :conditions => [ :user_id => [4, 0] ]) # 8 rows