I have a Drupal view that shows related contacts, and I noticed that it wasn't matching what I was seeing in the Civi relationships tabs on the relevant contacts. There were contacts displayed in the Drupal view with no relationships listed between those contacts in the Civi view.

Some digging reveals (I think), that the Drupal view is using the relationship table and the Civi view is using the relationship_cache table, and some further digging makes me concerned something isn't flowing correctly.

The specific example I'm looking at, there are relationships in the relationship table that do not exist in the relationship_cache table (and vice versa). I'm trying to work out any way of seeing these relationships in SearchKit or anywhere else in the interface, but the connections aren't appearing. They are in the database (and the Drupal view), but not accessible through Civi seemingly.

Some data points:

  • the relationship table has approximately 23,000 relationships
  • the relationship_cache table has approximately 25,000 relationships

I've read stuff about regenerating the cache table, but it really seems like the cache table is more accurate/current, or at least the non-cache table seems to have some out dated info.

I'm not clear on how the two tables really relate nor how to navigate out of the problem.

1 Answer 1


The civicrm_relationship table is the canonical source of relationship data. It is a read/write table and will contain all the current records.

The civicrm_relationship_cache is a read-only copy of the data. It will never be more current or correct, because it only ever copies data from the other table.

civicrm_relationship_cache should always contain exactly 2x number of rows as civicrm_relationship because it copies each relationship twice (once from the POV of each contact).

It should always stay in-sync unless something goes wrong with your SQL triggers, in that case there is a system check which will automatically alert you and allow you to fix the problem with one click:

enter image description here

  • OK, I think that makes sense to me, and I don't see that warning so I'm probably good on that point. Do you have any suggestion about why I have relationships in the relationship table that do not appear on the relationship tabs of either contact?
    – zip
    Feb 22 at 16:14
  • Oh, and the "exactly 2x" isn't what I am seeing... does that indicate a problem?
    – zip
    Feb 22 at 16:16
  • 1
    The system check was added fairly recently so if you haven't upgraded since January you won't have it. Try just running the command to rebuild the table.
    – Coleman
    Feb 22 at 16:40
  • We're on 5.69.2 so I would assume fairly up to date. When I run cv api4 RelationshipCache.rebuild I get "Api RelationshipCache rebuild version 4 does not exist." I tried instead this command from another post (Might have been your answer then too!): cv ev 'CRM_Contact_BAO_RelationshipCache::rebuild();' That does look like it rebuild the cache. I'll explore whether that fixes/answers my issues. Thanks.
    – zip
    Feb 22 at 17:22

Your Answer

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

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