+ # search all "searchable" columns of this table for query_str.
+ def self.search_for_user(user, query_str)
+ return [] unless self.searchable?
+ ilikes = []
+ ilike_params = []
+ self.searchable_columns.each do |column|
+ ilikes << "#{table_name}.#{column} ilike ?"
+ ilike_params << "%#{query_str}%"
+ end
+ if ilikes.empty?
+ return []
+ else
+ query_conditions = [ ilikes.join(' or ') ] + ilike_params
+ return self.readable_by(user).where(query_conditions)
+ end
+ end
+