From cc19cefe708baae3fc082ab6b46628c97f4a82ef Mon Sep 17 00:00:00 2001 From: Kyle Ferrara Date: Wed, 23 Mar 2022 06:09:21 +0200 Subject: [PATCH] [Mysql] small updated to quote table names. Mysql 8 has keywords that might match table names which cause an exception when selecting with the dleted/deleted at columns. (#512) --- lib/paranoia.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paranoia.rb b/lib/paranoia.rb index 959e5534..57bdf16e 100644 --- a/lib/paranoia.rb +++ b/lib/paranoia.rb @@ -40,7 +40,7 @@ def only_deleted # these will not match != sentinel value because "NULL != value" is # NULL under the sql standard # Scoping with the table_name is mandatory to avoid ambiguous errors when joining tables. - scoped_quoted_paranoia_column = "#{self.table_name}.#{connection.quote_column_name(paranoia_column)}" + scoped_quoted_paranoia_column = "#{connection.quote_table_name(self.table_name)}.#{connection.quote_column_name(paranoia_column)}" with_deleted.where("#{scoped_quoted_paranoia_column} IS NULL OR #{scoped_quoted_paranoia_column} != ?", paranoia_sentinel_value) end alias_method :deleted, :only_deleted