【问题标题】:Rails3 Arel Building the Where ClauseRails3 Arel 构建 Where 子句
【发布时间】:2013-08-09 16:56:51
【问题描述】:

我正在尝试使用 AREL 构建 where 子句,但这不会执行查询:

 rec = self.where('color' => color_passed)
 rec = rec.where('make' => make_passed) if make_passed.present?
 rec = rec.where('year' => year_passed) if year_passed.present?

如何根据某些条件正确附加 where 条件?

【问题讨论】:

    标签: ruby-on-rails-3 arel


    【解决方案1】:

    不执行是什么意思? where只返回一个Relation对象,你必须调用all才能得到结果:

    rec.all
    

    【讨论】:

    • 那行得通。我以为我不需要做 .all ,因为当我不做所有附加操作时它会起作用。 AREL 的新手。来自 rails2。
    猜你喜欢
    • 2011-05-31
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2011-08-14
    • 2011-09-07
    • 1970-01-01
    相关资源
    最近更新 更多