From 93c08c5304d444e1df7e3d968640484ca3566eef Mon Sep 17 00:00:00 2001 From: 0llirocks <4518617+0llirocks@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:28:44 +0200 Subject: [PATCH] Update active_record_adapter.rb for postgresql PostgreSQL can't compare null values, IS NULL must be used instead. --- lib/cancan/model_adapters/active_record_adapter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cancan/model_adapters/active_record_adapter.rb b/lib/cancan/model_adapters/active_record_adapter.rb index 33766c0a..d0a406be 100644 --- a/lib/cancan/model_adapters/active_record_adapter.rb +++ b/lib/cancan/model_adapters/active_record_adapter.rb @@ -198,11 +198,11 @@ def merge_non_empty_conditions(behavior, conditions_hash, sql) conditions = sanitize_sql(conditions_hash) case sql when true_sql - behavior ? true_sql : "not (#{conditions})" + behavior ? true_sql : "(not (#{conditions}) OR (#{conditions}) IS NULL)" when false_sql behavior ? conditions : false_sql else - behavior ? "(#{conditions}) OR (#{sql})" : "not (#{conditions}) AND (#{sql})" + behavior ? "(#{conditions}) OR (#{sql})" : "(not (#{conditions}) OR (#{conditions}) IS NULL) AND (#{sql})" end end