15781: Adds support for JSONB 'contains' filter.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 30 Jan 2020 14:05:32 +0000 (11:05 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 30 Jan 2020 14:05:32 +0000 (11:05 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/lib/record_filters.rb

index 994e8503106ad6ec3e931e555f2f28d8d455a1da..e059a6e70aaaba664af9ca5fd428d765ff4201ee 100644 (file)
@@ -19,7 +19,7 @@ module RecordFilters
   # +model_class+    subclass of ActiveRecord being filtered
   #
   # Output:
-  # Hash with two keys:
+  # Hash with the following keys:
   # :cond_out  array of SQL fragments for each filter expression
   # :param_out array of values for parameter substitution in cond_out
   # :joins     array of joins: either [] or ["JOIN containers ON ..."]
@@ -140,6 +140,9 @@ module RecordFilters
               raise ArgumentError.new("Invalid operand '#{operand}' for '#{operator}' must be true or false")
             end
             param_out << proppath
+          when 'contains'
+            cond_out << "#{attr_table_name}.#{attr} @> ?::jsonb"
+            param_out << SafeJSON.dump({proppath => [operand]})
           else
             raise ArgumentError.new("Invalid operator for subproperty search '#{operator}'")
           end