CRM Relationship cache

Created on 30 May 2025, 9 days ago

Problem/Motivation

Looking up contact is more complicated because there are two contacts per relationship.

Steps to reproduce

Proposed resolution

Create a table 'crm_relationship_cache'

function crm_schema() {
  $schema['crm_relationship_cache'] = [
    'description' => 'Stores relationships between entities.',
    'fields' => [
      'id' => [
        'type' => 'serial',
        'not null' => TRUE,
      ],
      'relationship_id' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'contact_id' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['id'],
  ];
  return $schema;
}

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bluegeek9

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bluegeek9
  • πŸ‡ΊπŸ‡ΈUnited States jdleonard Austin, TX, USA

    Is an example of the reason to do this creating a view that lists a contact's siblings and having a single table to join to find all the siblings?

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    Is an example of the reason to do this creating a view that lists a contact's siblings and having a single table to join to find all the siblings?

    No, this is to get all the relationships for a contact.

    Do you think we should add the bundle name?

  • πŸ‡ΊπŸ‡ΈUnited States jdleonard Austin, TX, USA

    Sorry, my previous question was unclear. I now get what we're doing here. This addresses my concern about creating Views showing a Contact's relationships so long as the table can be relied upon to be up-to-date. The term "cache" implies to me that it can't. Assuming that this table is always updated whenever relationships are added/removed/updated, I think it might make sense to find a name without "cache".

    I don't think it's necessary to add the bundle name. A given Contact is unlikely to have a ton of Relationships so an extra join from this table to the Relationships table to filter by Relationship Type won't be too onerous. However, I'm not opposed to including it and, eventually, performance testing might suggest doing so.

    Given the apparent need for this table, I wonder whether it would make sense to revisit the concept of one Relationship entity per direction of the relationship. Only because it would eliminate the need for this table.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    I am not sure if this table is necessary. I created the issue to have the discussion.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    What if contact_a and contact_b fields where replace with a contacts field. It will still be two contacts, and the contact ids are in the same column. This would serve the same purpose as the cache table.

  • πŸ‡ΊπŸ‡ΈUnited States jdleonard Austin, TX, USA

    That makes sense. I assume delta 0 would be Contact A, delta 1 would be Contact B, and the corresponding label fields would remain?

Production build 0.71.5 2024