Skip to content

Commit 61334cb

Browse files
authored
Update joins.md
1 parent 2083d46 commit 61334cb

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/Schema/joins.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,60 @@ dimensions: {
162162
}
163163
}
164164
```
165+
166+
## Transitive joins
167+
168+
> **NOTE:** Join graph is directed and `A-B` join is different from `B-A`. [Learn more about it here](direction-of-joins).
169+
170+
Cube.js automatically takes care of transitive joins. For example if you have following schema:
171+
172+
```javascript
173+
cube(`A`, {
174+
// ...
175+
joins: {
176+
B: {
177+
sql: `${A}.b_id = ${B}.id`,
178+
relationship: `belongsTo`
179+
}
180+
},
181+
182+
measures: {
183+
count: {
184+
type: `count`
185+
}
186+
}
187+
});
188+
189+
cube(`B`, {
190+
// ...
191+
joins: {
192+
C: {
193+
sql: `${B}.c_id = ${C}.id`,
194+
relationship: `belongsTo`
195+
}
196+
}
197+
});
198+
199+
cube(`C`, {
200+
// ...
201+
202+
dimensions: {
203+
category: {
204+
sql: `category`,
205+
type: `string`
206+
}
207+
}
208+
});
209+
```
210+
211+
And following query:
212+
213+
```javascript
214+
{
215+
measures: ['A.count'],
216+
dimensions: ['C.category']
217+
}
218+
```
219+
220+
Joins `A-B` and `B-C` will be resolved automatically.
221+
Cube.js uses [Dijkstra algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) to find join path between cubes given requested members.

0 commit comments

Comments
 (0)