From a596a58e0114b8fa8815bd76334857bef5334522 Mon Sep 17 00:00:00 2001 From: Miles Zimmerman Date: Wed, 2 Feb 2022 22:14:46 -0800 Subject: [PATCH] feat: active_record adapter #filter_array_eq and #filter_array_not_eq --- lib/graphiti/adapters/active_record.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/graphiti/adapters/active_record.rb b/lib/graphiti/adapters/active_record.rb index 79107652..f4883659 100644 --- a/lib/graphiti/adapters/active_record.rb +++ b/lib/graphiti/adapters/active_record.rb @@ -38,6 +38,20 @@ def filter_not_eq(scope, attribute, value) alias_method :filter_uuid_not_eq, :filter_not_eq alias_method :filter_enum_not_eq, :filter_not_eq + def filter_array_eq(scope, attribute, value) + if value.is_a?(Array) + value = value.map(&:to_s).join(',') + end + scope.where("#{attribute} @> ?", "{ #{value} }") + end + + def filter_array_not_eq(scope, attribute, value) + if value.is_a?(Array) + value = value.map(&:to_s).join(',') + end + scope.where.not("#{attribute} @> ?", "{ #{value} }") + end + def filter_string_eq(scope, attribute, value, is_not: false) column = column_for(scope, attribute) clause = column.lower.eq_any(value.map(&:downcase))