From db2b388ce8d1b3367e55fd4ac66e7b1741555079 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 19 Aug 2013 20:33:32 -0700 Subject: [PATCH] DO NOT MERGE patch for CRM-12840 by Jamie McClelland --- CRM/Contact/Selector.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CRM/Contact/Selector.php b/CRM/Contact/Selector.php index 31d1aa2fb1..ebe9c15b07 100644 --- a/CRM/Contact/Selector.php +++ b/CRM/Contact/Selector.php @@ -911,6 +911,13 @@ SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.dis $sql = str_replace($replaceSQL, $insertSQL, $sql); + // The prevnext_cache does not need to be in order, and the ORDER BY clause + // can break the query if it we're in advanced search and we are using a + // search view that uses fields not in the civicrm_contact table. + // See: 12840. + if(preg_match('/(.*) ORDER BY .*/is',$sql, $matches)) { + $sql = $matches[1]; + } CRM_Core_Error::ignoreException(); $result = CRM_Core_DAO::executeQuery($sql); -- 2.25.1