Add comment for IS NOT NULL in moving custom fields
authorlarssandergreen <lars@wildsight.ca>
Wed, 13 Sep 2023 20:23:42 +0000 (14:23 -0600)
committerlarssandergreen <lars@wildsight.ca>
Wed, 13 Sep 2023 20:23:42 +0000 (14:23 -0600)
CRM/Core/BAO/CustomField.php

index 496c176c98c830d460a4d610355016afca3b4f21..1151a85560fc9491d37941249d784bd98b91f538 100644 (file)
@@ -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