Skip to content

Linked row caches stay stale when relationship table definitions change #302

Description

@dajiaohuang

Describe the bug

Replacing a relationship definition can leave getLinkedRowIds returning the old chain when a linked-row listener is registered. The listener is also not notified of the changed result. The same replacement without a listener returns the correct result.

This occurs when changing either the local or remote table makes a self-table relationship become cross-table, or vice versa, while the row-to-remote-row values stay the same.

Steps to reproduce

import {createRelationships, createStore} from 'tinybase';

const table = {a: {next: 'b'}, b: {next: 'c'}};
const store = createStore().setTables({t: table, other: table});
const relationships = createRelationships(store)
  .setRelationshipDefinition('r', 't', 't', 'next');
const notifications = [];
relationships.addLinkedRowIdsListener('r', 'a', (current) => {
  notifications.push(current.getLinkedRowIds('r', 'a'));
});

relationships.setRelationshipDefinition('r', 't', 'other', 'next');
console.log(relationships.getRemoteTableId('r')); // 'other'
console.log(relationships.getLinkedRowIds('r', 'a')); // ['a', 'b', 'c']
console.log(notifications); // []

Expected behavior

The linked result should be ['a'] for a cross-table relationship, and the listener should receive that change. Removing the listener registration from the reproduction already yields ['a'].

Platform

  • Windows, Node.js v24.14.1
  • Current main commit: f09e5a3 (package version 9.7.0)
  • Reproduced from unmodified commit sources and with the native test build.

Additional context

The existing definition helper recalculates row values, but replacing just the table pairing can leave those values unchanged. Listener-backed linked-row caches still need to reflect the new definition. Regression coverage should also retain notifications after removing one of multiple listeners for the same starting row, and avoid new notifications when the linked result is unchanged.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions