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.
Describe the bug
Replacing a relationship definition can leave
getLinkedRowIdsreturning 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
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
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.