From 4c09447511791f26ad15892d18bd178b6f49cfcf Mon Sep 17 00:00:00 2001 From: larssandergreen Date: Wed, 13 Sep 2023 14:23:42 -0600 Subject: [PATCH] Add comment for IS NOT NULL in moving custom fields --- CRM/Core/BAO/CustomField.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 496c176c98..1151a85560 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -2043,6 +2043,9 @@ WHERE id IN ( %1, %2 ) $add->custom_group_id = $newGroup->id; self::createField($add, 'add'); + // IS NOT NULL needed here to prevent NULL values from being inserted when a field is moving from one entity type to another. + // It will pass _moveFieldValidate if all values are NULL, + // but will break things to try to insert NULL values for entity ids that make no sense for the new entity type. $sql = "INSERT INTO {$newGroup->table_name} (entity_id, `{$field->column_name}`) SELECT entity_id, `{$field->column_name}` FROM {$oldGroup->table_name} WHERE `{$field->column_name}` IS NOT NULL -- 2.25.1