新手问题 Ruby on Rails 有关数据查询语句的条件设定的问题

msm · April 19, 2015 · Last by msm replied at April 27, 2015 · 1583 hits

在阅读一篇讲述 ruby on rails 有关数据查询的文章时,遇到一个例子看不懂,贴上来

events = Event.where( ["capacity >= ?", 20 ] ).limit(3).order("id desc") 上述语句的查询条件看不懂,求解,谢谢! 说明:该查询针对的数据表有四个数据,分别是 name:string description:text is_public:boolean capacity:integer

查文档,看看where, limitorder都是什么意思就明白了。

capacity 大于等于 20 的前三条,按照 id 倒叙。‘capacity >= ?’ ?是变量占位符。。。这么做是出于安全考虑。

谢谢耐心解答,明白了。

You need to Sign in before reply, if you don't have an account, please Sign up first.