【问题标题】:Rails named queries to grailsRails 命名为 grails 的查询
【发布时间】:2015-07-28 02:11:47
【问题描述】:

我在rails中有这个:

default_scope { order('created_at DESC') }
  scope :by_source_name, ->(source_name) { where('source_name = ?', source_name) if source_name }
  scope :by_check_name,  ->(check_name)  { where('check_name = ?', check_name.upcase) if check_name }
  scope :by_status,      ->(status)      { where('status = ?', status.upcase) if status }
end

def index
    @alerts = Alert.by_source_name(params[:source_name])
                   .by_check_name(params[:check_name])
                   .by_status(params[:status])
    render json: @alerts, each_serializer: AlertSerializer
  end

如何转换成grails?

【问题讨论】:

  • 到目前为止你做了什么?
  • 嗯,不知道你能不能用闭包做到这一点?
  • 但这是 grails 社区,我们将如何阅读您的 rails 查询?至少把它改成伪代码。

标签: ruby-on-rails grails chaining named-query


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 2012-04-17
  • 2016-01-12
  • 1970-01-01
  • 2012-02-08
  • 2016-01-13
  • 1970-01-01
相关资源
最近更新 更多