Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonganger/b9a9d283f96c08e02dcb18c90dc94782 to your computer and use it in GitHub Desktop.
Save westonganger/b9a9d283f96c08e02dcb18c90dc94782 to your computer and use it in GitHub Desktop.
Fix Arel.sql deprecation warnings & errors in Rails 5.2/6+
### config/initializers/arel_sql_monkey_patch.rb
ActiveRecord::Relation.class_eval do
### FIX ERRORS FOR Arel.sql in Rails 6+
### FIX DEPRECATION WARNINGS FOR Arel.sql in Rails =5.2
if Rails::VERSION::STRING.to_f >= 5.2
def pluck(*args)
if args.any?{|x| x.is_a?(String) }
new_args = args.map{|x| x.is_a?(String) ? Arel.sql(x) : x }
super(*new_args)
else
super
end
end
def order(*args)
if args.any?{|x| x.is_a?(String) }
new_args = args.map{|x| x.is_a?(String) ? Arel.sql(x) : x }
super(*new_args)
else
super
end
end
def reorder(*args)
if args.any?{|x| x.is_a?(String) }
new_args = args.map{|x| x.is_a?(String) ? Arel.sql(x) : x }
super(*new_args)
else
super
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment