1

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 , 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.

1
  • Did you try the action update? Sometimes there is a difference between create and update. Nov 1, 2015 at 19:12

1 Answer 1

0

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 , 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 ...  **  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.