开发者

Rails/ActiveRecord: Syntax for "or" conditions?

Just trying to figure out how to write "or" statements in activerecord condit开发者_StackOverflow社区ions without resorting to raw sql - I assume it can be done, but google isn't helping much.

So, to give an example, suppose there's a model "Author" with a one-to-many relationship with 'Books' and a many-to-one relationship with 'Publisher'. How would I find all authors who have a publisher with name "Penguin" OR a book released in 2010 (or both) without resorting to SQL?

Any suggestions much appreciated


You can do that in :condition options

User.all(:conditions => ['xxx= ? OR yyy=?', x_valu, y_value])
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜