TinyBase logoTinyBase

getRemoteRowId

The getRemoteRowId method gets the remote Row Id for a given local Row in a Relationship.

getRemoteRowId(
  relationshipId: string,
  localRowId: string,
): undefined | string
TypeDescription
relationshipIdstring

The Id of the Relationship.

localRowIdstring

The Id of the local Row in the Relationship.

returnsundefined | string

The remote Row Id in the Relationship, or undefined.

If the identified Relationship or Row does not exist (or if the definition references a Table that does not exist) then undefined is returned.

Example

This example creates a Store, creates a Relationships object, and defines a simple Relationship. It then uses getRemoteRowId to see the remote Row Id in the Relationship (and also the remote Row Ids for a local 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'},
    felix: {species: 'cat'},
    cujo: {species: 'dog'},
  })
  .setTable('species', {
    dog: {price: 5},
    cat: {price: 4},
  });

const relationships = createRelationships(store);
relationships.setRelationshipDefinition(
  'petSpecies',
  'pets',
  'species',
  'species',
);

console.log(relationships.getRemoteRowId('petSpecies', 'fido'));
// -> 'dog'
console.log(relationships.getRemoteRowId('petSpecies', 'toto'));
// -> undefined
console.log(relationships.getRemoteRowId('petColor', 'fido'));
// -> undefined

Since

v1.0.0