From 85de3866df5f2b5fa1b821adcf27ec7e59ad4a07 Mon Sep 17 00:00:00 2001 From: torleifw Date: Thu, 18 Jul 2013 11:33:27 +1200 Subject: [PATCH] FIX postgres can filter on non text fields Filtering non text fields in postgres would cause the SQL to fail. This casts the field to text before the LIKE filter. --- search/filters/PartialMatchFilter.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/search/filters/PartialMatchFilter.php b/search/filters/PartialMatchFilter.php index 418e1975c..90c764963 100644 --- a/search/filters/PartialMatchFilter.php +++ b/search/filters/PartialMatchFilter.php @@ -16,13 +16,14 @@ class PartialMatchFilter extends SearchFilter { $this->model = $query->applyRelation($this->relation); $where = array(); $comparison = (DB::getConn() instanceof PostgreSQLDatabase) ? 'ILIKE' : 'LIKE'; + $dbname = (DB::getConn() instanceof PostgreSQLDatabase) ? $this->getDbName().'::text' : $this->getDbName(); if(is_array($this->getValue())) { foreach($this->getValue() as $value) { - $where[]= sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($value)); + $where[]= sprintf("%s %s '%%%s%%'", $dbname, $comparison, Convert::raw2sql($value)); } } else { - $where[] = sprintf("%s %s '%%%s%%'", $this->getDbName(), $comparison, Convert::raw2sql($this->getValue())); + $where[] = sprintf("%s %s '%%%s%%'", $dbname, $comparison, Convert::raw2sql($this->getValue())); } return $query->where(implode(' OR ', $where));