From c7a9da2a70f4443ec89d40f9aff798b33bd5d3a9 Mon Sep 17 00:00:00 2001 From: kreintjes Date: Thu, 30 Jan 2020 23:10:15 +0100 Subject: [PATCH] Also use Arel asc/desc when custom order is SqlLiteral (#73) Fixes 'Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s)' deprecation warning in Rails 5.2+ --- CHANGELOG.md | 2 ++ lib/wice_grid.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f05e3d1a..e914e3cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased +* Fix bug in "Dangerous query methods" deprecation warning fix in custom order when using Arel.sql + ## 4.1.0 (28 November, 2018) * Add option `filter_control_options` to columns. Initial use is to pass in the options `start_year`, `end_year`, and `max_year_allowed` when using `rails_datetime_helper` - [#12](https://github.com/patricklindsay/wice_grid/pull/18) diff --git a/lib/wice_grid.rb b/lib/wice_grid.rb index 83ebc0ce..20641de9 100644 --- a/lib/wice_grid.rb +++ b/lib/wice_grid.rb @@ -304,7 +304,7 @@ def form_ar_options(opts = {}) #:nodoc: else @ar_options[:order] = arel_column_reference(@status[:order]) end - if @ar_options[:order].is_a?(Arel::Attributes::Attribute) + if @ar_options[:order].is_a?(Arel::Attributes::Attribute) || @ar_options[:order].is_a?(Arel::Nodes::SqlLiteral) if @status[:order_direction] == 'desc' @ar_options[:order] = @ar_options[:order].desc else