Search code examples
ruby-on-railsgrailschainingnamed-query

Rails named queries to grails


I have this in 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

How to convert to grails?


Solution

  • Here is an example of named query - https://www.google.com.sg/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0CDIQFjAD&url=https%3A%2F%2Fspring.io%2Fblog%2F2010%2F05%2F24%2Fmore-grails-1-3-features&ei=wdFWVd2LAYiD8gXBmIGAAw&usg=AFQjCNG9nkkOhP3zR6CnwFm2n9EjUfOnmA&sig2=g-LwWYCjfK-U8gqydirRIg&bvm=bv.93564037,d.dGc