Rails 对 grails 的命名查询
Rails named queries to grails
我在 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?
我在 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?