getLinkedRowIds
The getLinkedRowIds
method gets the linked Row
Ids
for a given Row
in a linked list Relationship
.
getLinkedRowIds(
relationshipId: string,
firstRowId: string,
): Ids
Type | Description | |
---|---|---|
relationshipId | string | The |
firstRowId | string | The |
returns | Ids | The linked |
A linked list Relationship
is one that has the same Table
specified as both local Table
Id
and remote Table
Id
, allowing you to create a sequence of Row
objects within that one Table
.
If the identified Relationship
or Row
does not exist (or if the definition references a Table
that does not exist) then an array containing just the first Row
Id
is returned.
Example
This example creates a Store
, creates a Relationships
object, and defines a simple linked list Relationship
. It then uses getLinkedRowIds to see the linked Row
Ids
in the Relationship
(and also the linked Row
Ids
for a Row
that does not exist, and for a Relationship
that has not been defined).
import {createRelationships, createStore} from 'tinybase';
const store = createStore().setTable('pets', {
fido: {species: 'dog', next: 'felix'},
felix: {species: 'cat', next: 'cujo'},
cujo: {species: 'dog'},
});
const relationships = createRelationships(store);
relationships.setRelationshipDefinition(
'petSequence',
'pets',
'pets',
'next',
);
console.log(relationships.getLinkedRowIds('petSequence', 'fido'));
// -> ['fido', 'felix', 'cujo']
console.log(relationships.getLinkedRowIds('petSequence', 'felix'));
// -> ['felix', 'cujo']
console.log(relationships.getLinkedRowIds('petSequence', 'toto'));
// -> ['toto']
console.log(relationships.getLinkedRowIds('petFriendships', 'fido'));
// -> ['fido']
Since
v1.0.0