Answers.Body: <p>Based on comments the relationship_cache table is incomplete. Since you've already rebuilt the triggers (missing triggers may have been the cause of it not getting populated), the cache just needs repopulating. Run this from the command line:</p>
  <pre><code>cv ev 'CRM_Contact_BAO_RelationshipCache::rebuild();'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-15T18:02:07.140Z
Answers.Text: Thank you @Demerit Your expertise and kindness saved me many hours.
Answers.UserDisplayName: kapn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-14T20:53:46.337Z
Answers.LastActivityDate: 2023-12-15T01:11:54.633Z
Answers.LastEditDate: 2023-12-15T01:11:54.633Z
Answers.UserDisplayName: Demerit
Body: <p>Yesterday I <a href="https://civicrm.stackexchange.com/questions/46075/pre-filling-no-longer-working-for-membership-contribution-form-with-inbound-con?noredirect=1#comment54504_46075">asked a question</a> that I thought expressed the problem I was having, but this morning as I tried to implement a fix, I realized that this CiviCRM site has a more serious problem.
  There is a fundamental problem with either or both of relationship data and relationship interfaces on a site I manage.</p>
  <p><strong>Contact Page symptoms:</strong></p>
  <ol>
  <li>for &quot;broken&quot; contacts (which is most of them), the relationships tab appears empty even if &quot;employer&quot; field is filled in on the individual contact summary page</li>
  <li>if I attempt to add the employer relationship on the relationships tab of either the individual or the org, I get an on-screen error saying the relationship exists.</li>
  <li>if I delete the employer field on the individual contact I can add the relationship on the relationships tab, but it doesn't appear and doesn't work.</li>
  </ol>
  <p>I have discovered I can &quot;repair&quot; an organizational contact by creating a new one and merging the old one into it. This seems to read the data and write it properly to the new contact. This has the obvious disadvantages of changing CID and also of being a tedious manual task. This seems to repair the relevant individual contact too, so it seems likely the data problem is in how the relationships are written.</p>
  <p>Is there a way to realistically examine the relevant data tables to see if there is a correctable problem? I do not know when the problem started.</p>
  <p>There are no visible back end errors in Civi or Apache.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-14T00:36:06.137Z
Comments.Text: This is possibly relationship_cache corruption? There should be 2x as many entries in this table as in the relationships table. I'd start with that.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-12-14T20:09:44.033Z
Comments.Text: Thanks @Demerit So armed with that information, I can confirm a problem there. There are 2159 rows in civicrm_relationship and only 222 rows in civicrm_relationship_cache. Is there a way to rebuild the cache? I tried the "rebuild triggers" function, but as I expected, that didn't seem to have an effect. I'm not afraid of command line mariadb, but I'm far from expert.
Comments.UserDisplayName: kapn
Tags: <contacts><relationships><contact-summary-editor>
Title: relationships no longer working as expected - data corruption?
ThreadText: # relationships no longer working as expected - data corruption?
  
  (Asked by: username_0 on 2023-12-13)
  
  Yesterday I [asked a question](https://civicrm.stackexchange.com/questions/46075/pre-filling-no-longer-working-for-membership-contribution-form-with-inbound-con?noredirect=1#comment54504_46075) that I thought expressed the problem I was having, but this morning as I tried to implement a fix, I realized that this CiviCRM site has a more serious problem.
  There is a fundamental problem with either or both of relationship data and relationship interfaces on a site I manage.
  
  **Contact Page symptoms:**
  
  1. for "broken" contacts (which is most of them), the relationships tab appears empty even if "employer" field is filled in on the individual contact summary page
  2. if I attempt to add the employer relationship on the relationships tab of either the individual or the org, I get an on-screen error saying the relationship exists.
  3. if I delete the employer field on the individual contact I can add the relationship on the relationships tab, but it doesn't appear and doesn't work.
  
  I have discovered I can "repair" an organizational contact by creating a new one and merging the old one into it. This seems to read the data and write it properly to the new contact. This has the obvious disadvantages of changing CID and also of being a tedious manual task. This seems to repair the relevant individual contact too, so it seems likely the data problem is in how the relationships are written.
  
  Is there a way to realistically examine the relevant data tables to see if there is a correctable problem? I do not know when the problem started.
  
  There are no visible back end errors in Civi or Apache.
  
  **Tags:** contacts, relationships, contact-summary-editor
  
  > **Comments:**
  > **username_1**: This is possibly relationship_cache corruption? There should be 2x as many entries in this table as in the relationships table. I'd start with that.  
  > **username_0**: Thanks @username_1 So armed with that information, I can confirm a problem there. There are 2159 rows in civicrm_relationship and only 222 rows in civicrm_relationship_cache. Is there a way to rebuild the cache? I tried the "rebuild triggers" function, but as I expected, that didn't seem to have an effect. I'm not afraid of command line mariadb, but I'm far from expert.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-12-14. Score: 4 | Accepted answer
  
  Based on comments the relationship\_cache table is incomplete. Since you've already rebuilt the triggers (missing triggers may have been the cause of it not getting populated), the cache just needs repopulating. Run this from the command line:
  
  ```
  cv ev 'CRM_Contact_BAO_RelationshipCache::rebuild();'
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you @username_1 Your expertise and kindness saved me many hours.  
  
  ---
  
  