From 2899f87761d7cd469237b1307c1fb3e7e42f0e56 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 12 Aug 2021 10:28:50 +1200 Subject: [PATCH] dev/core#2743 fix api v3 to not unnecessarily load options --- api/v3/utils.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/v3/utils.php b/api/v3/utils.php index cc2ee37cad..d3d6c882a7 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -2078,9 +2078,14 @@ function _civicrm_api3_validate_integer(&$params, $fieldName, &$fieldInfo, $enti $fieldValue = NULL; } } - if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || $fieldName === 'campaign_id') { + if ( + (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || $fieldName === 'campaign_id') + // if it is already numeric AND it is an FK field we don't need to validate because + // sql will do that for us on insert (this also saves a big lookup) + && (!is_numeric($fieldValue) || empty($fieldInfo['FKClassName'])) + ) { $additional_lookup_params = []; - if (strtolower($entity) == 'address' && $fieldName == 'state_province_id') { + if (strtolower($entity) === 'address' && $fieldName == 'state_province_id') { $country_id = _civicrm_api3_resolve_country_id($params); if (!empty($country_id)) { $additional_lookup_params = ['country_id' => $country_id]; -- 2.25.1