开发者

How do I find records matching attribute with 1+ values in ActiveRecord/SQL?

How do I find records matching attribute with 1+ values in ActiveRecord/SQL? Examples would be something like:

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

How can I do this? The number of values will be no more than 10 I'd sa开发者_JAVA技巧y.


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

Or:

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

That should produce the following SQL:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜