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');
精彩评论