Can now use 'contains' to query individual columns in where() queries, not just any...
authorPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 4 Feb 2014 15:25:23 +0000 (10:25 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 4 Feb 2014 15:25:23 +0000 (10:25 -0500)
services/api/app/controllers/application_controller.rb

index dcb9c0c0d8deedcdb73a9f566d4756e6ee079b2e..c379cee80f44ac904a25ef00de1688cb779f47d7 100644 (file)
@@ -137,6 +137,7 @@ class ApplicationController < ActionController::Base
       @where.each do |attr,value|
         if attr == :any
           if value.is_a?(Array) and
+              value.length == 2 and
               value[0] == 'contains' and
               model_class.columns.collect(&:name).index('name') then
             ilikes = []
@@ -154,8 +155,13 @@ class ApplicationController < ActionController::Base
             conditions[0] << " and #{table_name}.#{attr} is ?"
             conditions << nil
           elsif value.is_a? Array
-            conditions[0] << " and #{table_name}.#{attr} in (?)"
-            conditions << value
+            if value[0] == 'contains' and value.length == 2
+              conditions[0] << "and #{table_name}.#{attr} ilike ?"
+              conditions << "%#{value[1]}%"
+            else
+              conditions[0] << " and #{table_name}.#{attr} in (?)"
+              conditions << value
+            end
           elsif value.is_a? String or value.is_a? Fixnum or value == true or value == false
             conditions[0] << " and #{table_name}.#{attr}=?"
             conditions << value