remove duplicate check when id is specified
authorTim Mallezie <tim.mallezie@chiro.be>
Tue, 14 Apr 2015 14:53:01 +0000 (16:53 +0200)
committerTim Mallezie <tim.mallezie@chiro.be>
Tue, 14 Apr 2015 14:53:01 +0000 (16:53 +0200)
CRM/Contact/BAO/Relationship.php

index 93ed52260df0d4d79697a8c08845c0e3103b9082..b3b87e6cb5a58a021fd5fbc144d4d6ae9e91c15f 100644 (file)
@@ -51,10 +51,14 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship {
    * @throws \CRM_Core_Exception
    */
   public static function create(&$params) {
-    $params = self::loadExistingRelationshipDetails($params);
-    if (self::checkDuplicateRelationship($params, $params['contact_id_a'], $params['contact_id_b'], CRM_Utils_Array::value('id', $params, 0))) {
+
+    $extended_params = self::loadExistingRelationshipDetails($params);
+    // When id is specified we always wan't to update, so we don't need to
+    // check for duplicate relations.
+    if (!isset($params['id']) && self::checkDuplicateRelationship($extended_params, $extended_params['contact_id_a'], $extended_params['contact_id_b'], CRM_Utils_Array::value('id', $extended_params, 0))) {
       throw new CRM_Core_Exception('Duplicate Relationship');
     }
+    $params = $extended_params;
     if (self::checkValidRelationship($params, $params, 0)) {
       throw new CRM_Core_Exception('Invalid Relationship');
     }