Answers.Body: <p>You will probably have to update the tables directly, and as you have figured out you will have to change civicrm_relationship. And of course try in a test environment first.</p>
  
  <p>You will have to make sure the relationship direction is changed in the civicrm interface (civicrm/admin/reltype?reset=1), and then update the civicrm_relationship table in the database. </p>
  
  <p>You can duplicate the civicrm_relationship table as civicrm_relationship2 and then use this second table to swap the a and b columns, in this example for relationship_type_id 5.</p>
  
  <pre><code>UPDATE civicrm_relationship, civicrm_relationship2
  SET civicrm_relationship.contact_id_a = civicrm_relationship2.contact_id_b, civicrm_relationship.contact_id_b = civicrm_relationship2.contact_id_a
  WHERE civicrm_relationship.id = civicrm_relationship2.id AND civicrm_relationship.relationship_type_id = 5
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-30T01:50:02.290Z
Answers.Text: Pretty sure one of those above should say civicrm_relationship_type
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-02T09:05:32.417Z
Answers.Text: pretty sure too, sorry about the typo!
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T06:48:36.477Z
Answers.LastActivityDate: 2015-10-01T12:42:13.307Z
Answers.LastEditDate: 2015-10-01T12:42:13.307Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>I agree with ErikH, but if you don't feel comfortable updating the database, you can...</p>
  
  <ul>
  <li><p>create a new relationship type with the opposite order (b_a vs a_b)</p></li>
  <li><p>do an advanced search, selecting only individuals with that<br>
  relationship</p></li>
  <li>select the action to "export" the contacts</li>
  <li><p>select two    fields (1)the internal contact_id and (2) the
  relationship type field    with the internal_contact_id  and export 
  (verify that you did this    correctly and the ids match as
  expected!)</p></li>
  <li><p>use civicrm import to    import the csv file to new relationship type
  created in the first    step.</p></li>
  </ul>
  
  <p>May more steps, but if you don't know how or want to mess with the database, this will work.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T21:13:47.597Z
Answers.Text: If your relationship has many to one  (i.e one individual is connected to many organizations) then the export will only pick one of the organizations, so you will want to do the advanced search on the organization not the individual.
Answers.UserDisplayName: pkeogan - BackOffice Thinking
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-29T21:11:46.183Z
Answers.LastActivityDate: 2015-09-29T21:11:46.183Z
Answers.UserDisplayName: pkeogan - BackOffice Thinking
Body: <p>I have made an organisation / individual relationship type as an <code>a_b</code> relationship while it should be a <code>b_a</code> relationship to be consistent with the existing relationships like employer of which always have a as individual (child) and b as organisation (parent).</p>
  
  <p>There are allready a lot of contacts that have this relationship in the database.</p>
  
  <p>I tried to change the direction of the relationship type at <code>civicrm/admin/reltype?action=update&amp;id=12&amp;reset=1</code> and then swap the data of the <code>contact_id_a</code> and <code>contact_id_b</code> columns in the database for that relation type id.  </p>
  
  <p>So what is the best way to change the direction (swap individual/organisation) of a relationship? 
  And what else has an influence on this except for the database tables of <code>civicrm_relationship</code> and <code>civicrm_relationship_type</code>?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-30T01:53:19.850Z
Comments.Text: Hans - what do you actually gain from doing this, other than 'consistency'? There may not be any logic/code that means the way you have it is 'wrong'
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-30T06:20:12.850Z
Comments.Text: If you use Drupal views you have to specify the relationship as a views relation and there you have to choose between an A or a B relationship. So if "employer of" is in a different direction then "organisation of" you cannot use 1 view to get them both in 1 column.
Comments.UserDisplayName: Hans Rossel
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-30T09:30:14.083Z
Comments.Text: ok thanks, though maybe you can get them as a second column and then concatenate those. btw we have just had to do this for more complex reason ie previous developers had set some memberships to inherit b>a and others a>b using the same relationship which was kind of nuts. I can probably pass over the query if you want to give it a go. let me know
Comments.UserDisplayName: petednz - fuzion
Tags: <relationships>
Title: How to change the direction of a relationship type with existing data
ThreadText: # How to change the direction of a relationship type with existing data
  
  (Asked by: username_0 on 2015-09-28)
  
  I have made an organisation / individual relationship type as an `a_b` relationship while it should be a `b_a` relationship to be consistent with the existing relationships like employer of which always have a as individual (child) and b as organisation (parent).
  
  There are allready a lot of contacts that have this relationship in the database.
  
  I tried to change the direction of the relationship type at `civicrm/admin/reltype?action=update&id=12&reset=1` and then swap the data of the `contact_id_a` and `contact_id_b` columns in the database for that relation type id.
  
  So what is the best way to change the direction (swap individual/organisation) of a relationship?
  And what else has an influence on this except for the database tables of `civicrm_relationship` and `civicrm_relationship_type`?
  
  **Tags:** relationships
  
  > **Comments:**
  > **username_1**: Hans - what do you actually gain from doing this, other than 'consistency'? There may not be any logic/code that means the way you have it is 'wrong'  
  > **username_0**: If you use Drupal views you have to specify the relationship as a views relation and there you have to choose between an A or a B relationship. So if "employer of" is in a different direction then "organisation of" you cannot use 1 view to get them both in 1 column.  
  > **username_1**: ok thanks, though maybe you can get them as a second column and then concatenate those. btw we have just had to do this for more complex reason ie previous developers had set some memberships to inherit b>a and others a>b using the same relationship which was kind of nuts. I can probably pass over the query if you want to give it a go. let me know  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2015-09-29. Score: 5 | Accepted answer
  
  I agree with ErikH, but if you don't feel comfortable updating the database, you can...
  
  * create a new relationship type with the opposite order (b\_a vs a\_b)
  * do an advanced search, selecting only individuals with that  
    relationship
  * select the action to "export" the contacts
  * select two fields (1)the internal contact\_id and (2) the
    relationship type field with the internal\_contact\_id and export
    (verify that you did this correctly and the ids match as
    expected!)
  * use civicrm import to import the csv file to new relationship type
    created in the first step.
  
  May more steps, but if you don't know how or want to mess with the database, this will work.
  
  > **Comments:**
  > **username_3**: If your relationship has many to one  (i.e one individual is connected to many organizations) then the export will only pick one of the organizations, so you will want to do the advanced search on the organization not the individual.  
  
  ---
  
  ### Answer by username_2 on 2015-09-29. Score: 4
  
  You will probably have to update the tables directly, and as you have figured out you will have to change civicrm_relationship. And of course try in a test environment first.
  You will have to make sure the relationship direction is changed in the civicrm interface (civicrm/admin/reltype?reset=1), and then update the civicrm_relationship table in the database. 
  You can duplicate the civicrm_relationship table as civicrm_relationship2 and then use this second table to swap the a and b columns, in this example for relationship_type_id 5.
  UPDATE civicrm_relationship, civicrm_relationship2
  SET civicrm_relationship.contact_id_a = civicrm_relationship2.contact_id_b, civicrm_relationship.contact_id_b = civicrm_relationship2.contact_id_a
  WHERE civicrm_relationship.id = civicrm_relationship2.id AND civicrm_relationship.relationship_type_id = 5
  
  > **Comments:**
  > **username_1**: Pretty sure one of those above should say civicrm_relationship_type  
  > **username_2**: pretty sure too, sorry about the typo!  
  
  ---
  
  