Query Follow Back
Move backwards and query with a different relation.
Description
Move backwards and query the same objects with a different relation, by stepping back after having followed a relation. The Query Follow Back function moves the cursor of a query backwards and the hops parameter specifies the number of steps to move back, and is optional with a default value of 1. This function should only be called on a query object that results from a Query Follow call. The result set will be in the form of a cross-join, where each tuple contains a pair of related objects. Example:
const people = [
{ name: "Alice", siblings: ["Bob", "Charlie"], children: ["David", "Eve"] },
{ name: "Bob", siblings: ["Alice", "Charlie"], children: [] },
{ name: "Charlie", siblings: ["Alice", "Bob"], children: ["Frank"] },
{ name: "David", siblings: ["Eve"], children: [] },
{ name: "Eve", siblings: ["David"], children: [] },
{ name: "Frank", siblings: ["Charlie"], children: [] },
];
const aliceQuery = Query.from(people[0]);
const siblingsQuery = aliceQuery.follow("siblings");
const result = siblingsQuery.back(1).follow("children").execute();
result is:
// [
// { siblings: "Bob", children: "David" },
// { siblings: "Bob", children: "Eve" },
// { siblings: "Charlie", children: "David" },
// { siblings: "Charlie", children: "Eve" },
// ]
Inputs
- query (Query)
- hops (Number)
Outputs
- query (Query)