如何在ActiveRecord / SQL中找到与1+值匹配的记录?

时间:2010-09-11 21:38:42

标签: sql activerecord

如何在ActiveRecord / SQL中找到与1+值匹配的记录?例如:

Post.find_by_type("Post and/or ChildPost")
Post.find(:type => "Post and/or ChildPost")

我该怎么做?我想说的数值不会超过10个。

1 个答案:

答案 0 :(得分:2)

Post.find :all, :conditions => ['type IN (?)', ['Post', 'ChildPost']]

或者:

values = ['Post', 'ChildPost']
Post.find :all, :conditions => ['type IN (?)', values]

这应该产生以下SQL:

SELECT * FROM `posts` WHERE `type` IN ('Post', 'ChildPost');