Confused by getobjectbyref

Hi Everyone,

I’m getting set up in SB right now, and excited to finally have a system with live query and dynamic content creation. I’ve been looking for this for a while. I feel like I’m missing something about getting objects.

Why does getobjectbyref need the tag? I have the ref, which is the unique reference. It would be really useful to query for an object, then once you have the ref that’s all you need. It seems strange to identify an object by “page”, “tag”, and ref, when the ref has both page and location on the page, and then who cares what the tag is if you have the ref?

And yes, I can just pass that stuff around, but sometimes I want to find a thing without caring about its tag, getObjectByRef seems to do that, but . . . it doesn’t. What’s it for?

1 Like

Refs are like id columns in relational databases. Generally you don’t have one such value unique across all entities/tables, they’re unique to that particular table. In SB it’s the same way, objects are indexed based on their tag (think: table) and ref (think: primary key) and therefore can only be (efficiently) looked up that way.

If you look at the xxxx_data indexeddb in your browser you’ll see this is how it’s stored per key:

This allows for efficiently querying all objects part of a tag (prefix based scanning), but not for lookups purely based on a ref.

Ah! I see. This

  • ref: a globally unique identifier, often represented as a pointer to the place (page, position) in your space where the object is defined. For instance, a page object will use the page name as its ref attribute, and a task will use page@pos (where pos is the location the task appears in page).

refers to the ‘ref’ as globally unique, which I think is what confused me. Thanks for the reply.

1 Like