Skip to main content

Crawling the Relationships: Part 1

Some predicates in our ledger are of type, ref, meaning they are references to other subjects in the ledger.

For example, our credit collection has the following predicates:

  • credit/actor
  • credit/order
  • credit/character
  • credit/id

The credit/actor predicate is a reference to subjects in the actor collection. If we issue the following query:

{
"select": ["*"],
"from": "credit"
}

We will get a response that looks like this:

{
"status": 200,
"result": [
{
"credit/id": "539d41f9c3a3683b50002b54",
"credit/character": "Russian Scientist (uncredited)",
"credit/order": 51,
"credit/actor": {
"_id": 4316442171115
},
"_id": 4312147271441
},
{
"credit/id": "56bcc6e3c3a36860e10038c0",
"credit/character": "Ambrose Cornell",
"credit/order": 16,
"credit/actor": {
"_id": 4316442147198
},
"_id": 4312147271440
}
"..."
]
}

As you can see, we don't automatically see any information about a given actor. We only see their _id, "credit/actor": {"_id": 4316442171115}. In order to view all the predicates for actors, we need to specify {"credit/actor": ["*"]} in our query:

{
"select": ["*", {"credit/actor": ["*"]}],
"from": "credit"
}

The above query will not only select all, "select": ["*", predicates from every credit, but select all predicates from the actors referenced in those credits,"select": ["*", {"credit/actor": ["*"]}].

The results will mirror the shape of our query:

{
"status": 200,
"result": [
{
"credit/id": "539d41f9c3a3683b50002b54",
"credit/character": "Russian Scientist (uncredited)",
"credit/order": 51,
"credit/actor": {
"actor/id": 1330815,
"actor/name": "Irena Marr",
"actor/gender": 0,
"_id": 4316442171115
},
"_id": 4312147271441
}
"..."
]
}

You can keep crawling the relationships as many times as you need, for example, we can select all movies, and crawl the relationships to get all credits in those movies and all actors in those credits. That query would look like:

{
"select": ["*", {"movie/credits": ["*", {"credit/actor": ["*"]}]}],
"from": "movie"
}