Created
March 26, 2023 03:38
-
-
Save westonganger/b9a9d283f96c08e02dcb18c90dc94782 to your computer and use it in GitHub Desktop.
Fix Arel.sql deprecation warnings & errors in Rails 5.2/6+
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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