Crawling the Relationships: Part 2
As we saw in the previous example, some predicates in our ledger are of type, ref
, meaning they are references to other subjects in the ledger.
In order to fully understand this concept, let's go through another example based off of our productionCompany
collection, which has the following predicates:
- productionCompany/name
- productionCompany/id
- productionCompany/country
The productionCompany/country
predicate is a reference to subjects in the country
collection. If we issue the following query:
{
"select": ["*"],
"from": "productionCompany"
}
We will get a response that looks like this:
{
"status": 200,
"result": [
{
"productionCompany/id": 94552,
"productionCompany/name": "Flatiron Pictures",
"productionCompany/country": {
"_id": 4299262268343
}
},
{
"productionCompany/id": 5486,
"productionCompany/name": "Darius Films",
"productionCompany/country": {
"_id": 4299262268342
}
},
{
"productionCompany/id": 11444,
"productionCompany/name": "Lumiere",
"productionCompany/country": {
"_id": 4299262268341
}
}
"..."
]
}
As you can see, we don't automatically see any information about where the production company is located. We only see their _id, "productionCompany/id": 94552
and their name, "productionCompany/name": "Lumiere"
. In order to view all the predicates for productionCompany, we need to specify {"productionCompany/country": ["*"]}
in our query:
{
"select": ["*", {"productionCompany/country": ["*"]}],
"from": "productionCompany"
}
The above query will not only select all, "select": ["*",
predicates from every productionCompany, but select all country predicates from the productionCompany referenced in country,"select": ["*", {"productionCompany/country": ["*"]}]
.
The results will mirror the shape of our query:
{
"status": 200,
"result": [
{
"productionCompany/id": 94552,
"productionCompany/name": "Flatiron Pictures",
"productionCompany/country": {
"country/iso_3166_1": "US",
"country/name": "United States of America",
"_id": 4303557230679
},
"_id": 4299262268343
}
"..."
]
}
** Note that there is no ref
to productionCompany in the country collection, so this query will not work! It is just listed here as an example.