开发者

Rails/ActiveRecord: Syntax for "or" conditions?

开发者 https://www.devze.com 2023-01-21 02:54 出处:网络
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.

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

精彩评论

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