`
hideto
  • 浏览: 2655507 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Rails宝典之第十五式: find条件

    博客分类:
  • Ruby
阅读更多
数据库查询的conditions除了简单的字符串,还可以用数组,range,nil等等,看看代码:
Task.find(:all, :conditions => ["complete=? and priority=?", false, 3])
Task.find(:all, :conditions => ["complete=? and priority IS ?", false, nil])
Task.find(:all, :conditions => ["complete=? and priority IN (?)", false, [1,3]])
Task.find(:all, :conditions => ["complete=? and priority IN (?)", false, 1..3])
Task.find(:all, :conditions => { :complete => false, :priority => 1 })
Task.find(:all, :conditions => { :complete => false, :priority => nil })
Task.find(:all, :conditions => { :complete => false, :priority => [1,3] })
Task.find(:all, :conditions => { :complete => false, :priority => 1..3 })
Task.find_all_by_priority(1..3)

find_by都可以使用数组、range、nil,确实不错。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics