Answers.Body: <p>After some debugging it has turned that  we have exactly same situation described here <a href="https://civicrm.stackexchange.com/questions/6725/how-to-change-the-direction-of-a-relationship-type-with-existing-data?rq=1">How to change the direction of a relationship type with existing data</a> , but we weren't aware that changing Relationship direction via GUI doesn't make change in a database. Sounds like another civicrm bug.  </p>
  
  <p>We've ended up by direct Mysql intervention with this query (in case someone will face this issue in future): </p>
  
  <pre><code>UPDATE 
   civicrm_relationship 
  SET 
    contact_id_a=contact_id_a+contact_id_b,
    contact_id_b=contact_id_a-contact_id_b,
    contact_id_a=contact_id_a-contact_id_b
  WHERE ** ... conditions set ...  **  
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-05T20:56:21.993Z
Answers.LastActivityDate: 2015-11-17T16:52:08.657Z
Answers.LastEditDate: 2017-04-13T12:53:13.167Z
Answers.UserDisplayName: yurg
Body: <p>While trying to alter Contact Relationships Permission ("Contact A can view and update information about Contact B") using this code:</p>
  
  <pre><code>$result = civicrm_api3('Relationship', 'create', array(
    'debug' =&gt; 1,
    'contact_id_a' =&gt; 111,
    'contact_id_b' =&gt; 111,
    'relationship_type_id' =&gt; 111,
    'id' =&gt; 111,
  'is_permission_a_b' =&gt; 0, /* &lt;- This was manually set as 1 and need to be altered */ 
  )); 
  </code></pre>
  
  <p>we've got "duplicate relationship" error message</p>
  
  <pre><code>"error_message": "Duplicate Relationship"
  </code></pre>
  
  <p>Deprecated "setvalue/update" suggestion is <em>"Use "create" with an id instead."</em> and we do have all IDs in place.  Does 'Create' for Relationships work as it works for Contacts or we've missed something? </p>
  
  <p><strong>UPDATE 1</strong><br>
  After some debugging it has turned that  we have exactly same situation described here <a href="https://civicrm.stackexchange.com/questions/6725/how-to-change-the-direction-of-a-relationship-type-with-existing-data?rq=1">How to change the direction of a relationship type with existing data</a> , but we weren't aware that changing Relationship direction via GUI doesn't make change in a database. Sounds like another civicrm bug.  </p>
  
  <p><strong>UPDATE 2</strong>
  Even after Relationship directions have been altered, same error "Duplicate Relationships" appears at an attempt to ALTER one of Relationship parameter  using CREATE Action via CiviCRM Api. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-01T19:12:57.610Z
Comments.Text: Did you try the action update? Sometimes there is a difference between create and update.
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Tags: <api><permissions><relationships>
Title: Batch alter Relationship Contact Permission only
ThreadText: # Batch alter Relationship Contact Permission only
  
  (Asked by: username_0 on 2015-10-30)
  
  While trying to alter Contact Relationships Permission ("Contact A can view and update information about Contact B") using this code:
  
  ```
  $result = civicrm_api3('Relationship', 'create', array(
    'debug' => 1,
    'contact_id_a' => 111,
    'contact_id_b' => 111,
    'relationship_type_id' => 111,
    'id' => 111,
  'is_permission_a_b' => 0, /* <- This was manually set as 1 and need to be altered */ 
  )); 
  
  ```
  
  we've got "duplicate relationship" error message
  
  ```
  "error_message": "Duplicate Relationship"
  
  ```
  
  Deprecated "setvalue/update" suggestion is *"Use "create" with an id instead."* and we do have all IDs in place. Does 'Create' for Relationships work as it works for Contacts or we've missed something?
  
  **UPDATE 1**  
  After some debugging it has turned that we have exactly same situation described here [How to change the direction of a relationship type with existing data](https://civicrm.stackexchange.com/questions/6725/how-to-change-the-direction-of-a-relationship-type-with-existing-data?rq=1) , but we weren't aware that changing Relationship direction via GUI doesn't make change in a database. Sounds like another civicrm bug.
  
  **UPDATE 2**
  Even after Relationship directions have been altered, same error "Duplicate Relationships" appears at an attempt to ALTER one of Relationship parameter using CREATE Action via CiviCRM Api.
  
  **Tags:** api, permissions, relationships
  
  > **Comments:**
  > **username_1**: Did you try the action update? Sometimes there is a difference between create and update.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-11-05. Score: 0 | Accepted answer
  
  After some debugging it has turned that we have exactly same situation described here [How to change the direction of a relationship type with existing data](https://civicrm.stackexchange.com/questions/6725/how-to-change-the-direction-of-a-relationship-type-with-existing-data?rq=1) , but we weren't aware that changing Relationship direction via GUI doesn't make change in a database. Sounds like another civicrm bug.
  
  We've ended up by direct Mysql intervention with this query (in case someone will face this issue in future):
  
  ```
  UPDATE 
   civicrm_relationship 
  SET 
    contact_id_a=contact_id_a+contact_id_b,
    contact_id_b=contact_id_a-contact_id_b,
    contact_id_a=contact_id_a-contact_id_b
  WHERE ** ... conditions set ...  **  
  
  ```
  
  
  ---
  
  