TinyBase logoTinyBase β

getLinkedRowIds

The getLinkedRowIds function returns a reactive object reflecting the linked Row Ids in a Relationship, and registers a listener so that any changes will update current.

getLinkedRowIds(
  relationshipId: MaybeGetter<string>,
  firstRowId: MaybeGetter<string>,
  relationshipsOrRelationshipsId?: MaybeGetter<undefined | RelationshipsOrRelationshipsId>,
): {current: Ids}
TypeDescription
relationshipIdMaybeGetter<string>

The Id of the Relationship (or a getter returning it).

firstRowIdMaybeGetter<string>

The Id of the first Row (or a getter returning it).

relationshipsOrRelationshipsId?MaybeGetter<undefined | RelationshipsOrRelationshipsId>

The Relationships object to use (plain or getter), or its Id.

returns{current: Ids}

A reactive object with a current Ids property.

Example

This example passes a TinyBase object into a Svelte component and reads the reactive object's current property.

App.svelte
<svelte:options runes={true} />

<script>
  import {getLinkedRowIds} from 'tinybase/ui-svelte';

  let {relationships} = $props();

  const result = getLinkedRowIds('nextPet', 'fido', relationships);
</script>

{JSON.stringify(result.current)}
import {flushSync, mount} from 'svelte';
import {createRelationships, createStore} from 'tinybase';
import App from './App.svelte';

const store = createStore()
  .setTables({
    pets: {
      fido: {species: 'dog', color: 'brown', sold: false, next: 'felix'},
      felix: {species: 'cat', color: 'black', sold: true},
    },
    species: {dog: {price: 5}, cat: {price: 4}},
  })
  .setValues({open: true, employees: 3});
const relationships = createRelationships(store)
  .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species')
  .setRelationshipDefinition('nextPet', 'pets', 'pets', 'next');
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {relationships}}));
console.log(app.textContent);
// -> '["fido","felix"]'

Since

v8.1.0