TinyBase logoTinyBase β

getRelationshipsStoreTableIds

The getRelationshipsStoreTableIds function returns the Store, local table Id, and remote table Id for a given Relationships object and relationship Id.

getRelationshipsStoreTableIds(
  relationshipsOrId: MaybeGetter<undefined | RelationshipsOrRelationshipsId>,
  relationshipId: MaybeGetter<string>,
): {
  store: Store | undefined;
  localTableId: Id | undefined;
  remoteTableId: Id | undefined;
}
TypeDescription
relationshipsOrIdMaybeGetter<undefined | RelationshipsOrRelationshipsId>

The Relationships object, its Id, or a getter returning either.

relationshipIdMaybeGetter<string>

The Id of the relationship, or a getter returning it.

returns{ store: Store | undefined; localTableId: Id | undefined; remoteTableId: Id | undefined; }

An object with store, localTableId, and remoteTableId getter properties.

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 {getRelationshipsStoreTableIds} from 'tinybase/ui-svelte';

  let {relationships} = $props();

  const result = getRelationshipsStoreTableIds(relationships, 'petSpecies');
</script>

{result.localTableId + ':' + result.remoteTableId}
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);
// -> 'pets:species'

Since

v8.1.0