开发者

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

开发者 https://www.devze.com 2023-01-16 00:06 出处:网络
How do I find records matching attribute with 1+ values in ActiveRecord/SQL?Examples would be something like:

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

精彩评论

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