From 7f31dda77c44d96d8991af085f2a65bfe90490a0 Mon Sep 17 00:00:00 2001 From: Mathew Date: Thu, 14 Nov 2024 13:43:41 +1100 Subject: [PATCH] dont attempt to optimise joins --- lib/cancan/rules_compressor.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/cancan/rules_compressor.rb b/lib/cancan/rules_compressor.rb index b4b9b5c5..8a470876 100644 --- a/lib/cancan/rules_compressor.rb +++ b/lib/cancan/rules_compressor.rb @@ -29,7 +29,11 @@ def simplify(rules) # e.g contact_id = 1, contact_id = [2, 3] => contact_id = [1, 2, 3] potentially_simplify_singular = rules.size > 1 && rules.all? do |rule| if rule.conditions.is_a?(Hash) - rule.conditions.size == 1 + # If there is only one column in the expressions, we can simplify it + # A hash of size one e.g { contact_id: [1,2] } or { contact_id: 1 } but not { contact: {id: 1}} + if rule.conditions.size == 1 + !rule.conditions.values.first.is_a?(Hash) + end else false end @@ -39,6 +43,7 @@ def simplify(rules) potentially_simplify_singular = rules.map do |rule| rule.conditions.keys.first end.uniq + if potentially_simplify_singular.size == 1 new_valid_values = rules.map do |rule| r = rule.conditions.values