Skip to content

Commit 47d566f

Browse files
docs: Update join relationship types (#6476)
* Update the joins page * Update legacy usages of many_to_one * Update legacy usages of many_to_one (2) * Update legacy usages of one_to_many * Update legacy usages of one_to_one * Clarify the disclaimer * Update docs/content/Examples-Tutorials-Recipes/Recipes/funnels.mdx Co-authored-by: Hassan Khan <[email protected]> * Update docs/content/Schema/Fundamentals/Working-with-Joins.mdx Co-authored-by: Hassan Khan <[email protected]> --------- Co-authored-by: Hassan Khan <[email protected]>
1 parent 424f534 commit 47d566f

File tree

14 files changed

+208
-191
lines changed

14 files changed

+208
-191
lines changed

docs/content/Caching/Getting-Started-Pre-Aggregations.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ receives via the API. The process for selection is summarized below:
167167

168168
- The pre-aggregation contains all dimensions, filter dimensions and leaf
169169
measures from the query
170-
- The measures aren't multiplied ([via a `hasMany`
171-
relation][ref-schema-joins-hasmany])
170+
- The measures aren't multiplied ([via a `one_to_many`
171+
relationship][ref-schema-joins-rel])
172172

173173
3. If no, then check if
174174

@@ -197,7 +197,7 @@ cube(`LineItems`, {
197197
joins: {
198198
Orders: {
199199
sql: `${CUBE}.order_id = ${Orders.id}`,
200-
relationship: `belongsTo`,
200+
relationship: `many_to_one`,
201201
},
202202
},
203203

@@ -425,7 +425,7 @@ To recap what we've learnt so far:
425425

426426
- **Additive measures** are measures whose values can be added together
427427

428-
- **Multiplied measures** are measures that define `hasMany` relations
428+
- **Multiplied measures** are measures that define `one_to_many` relationships
429429

430430
- **Leaf measures** are measures that do not reference any other measures in
431431
their definition
@@ -488,7 +488,7 @@ Some extra considerations for pre-aggregation selection:
488488
/caching/using-pre-aggregations#pre-aggregations-storage
489489
[ref-schema-dims]: /schema/reference/dimensions
490490
[ref-schema-joins]: /schema/reference/joins
491-
[ref-schema-joins-hasmany]: /schema/reference/joins#relationship
491+
[ref-schema-joins-rel]: /schema/reference/joins#relationship
492492
[ref-schema-preaggs]: /schema/reference/pre-aggregations
493493
[ref-schema-preaggs-origsql]:
494494
/schema/reference/pre-aggregations#type-originalsql

docs/content/Caching/Using-Pre-Aggregations.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ cube(`Orders`, {
582582
joins: {
583583
Users: {
584584
sql: `${CUBE.user_id} = ${Users.id}`,
585-
relationship: `belongsTo`
585+
relationship: `many_to_one`
586586
},
587587
},
588588
});

docs/content/Examples-Tutorials-Recipes/Recipes/column-based-access.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To implement column-based access, we will use supplier's email from a
1919
[`queryRewrite`](https://cube.dev/docs/security/context#using-query-rewrite)
2020
extension point to manage data access.
2121

22-
We have `Products` and `Suppliers` cubes with a `hasOne` relationship from
22+
We have `Products` and `Suppliers` cubes with a `many_to_one` relationship from
2323
products to suppliers:
2424

2525
```javascript
@@ -28,7 +28,7 @@ cube(`Products`, {
2828

2929
joins: {
3030
Suppliers: {
31-
relationship: `belongsTo`,
31+
relationship: `many_to_one`,
3232
sql: `${CUBE}.supplier_id = ${Suppliers.id}`,
3333
},
3434
},

docs/content/Examples-Tutorials-Recipes/Recipes/entity-attribute-value.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cube(`Users`, {
2626

2727
joins: {
2828
Orders: {
29-
relationship: 'hasMany',
29+
relationship: 'one_to_many',
3030
sql: `${CUBE}.id = ${Orders.userId}`,
3131
},
3232
},

docs/content/Examples-Tutorials-Recipes/Recipes/event-analytics.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,10 @@ The next step is to identify the events contained within the session and the
254254
events ending the session. It’s required to get metrics such as session duration
255255
and events per session, or to identify sessions where specific events occurred
256256
(we’re going to use that for funnel analysis later on). We’re going to
257-
[declare join](/schema/reference/joins), that Events `belongsTo` Sessions and a
258-
specify condition, such as all users' events from session start (inclusive) till
259-
the start of the next session (exclusive) belong to that session.
257+
[declare a join](/schema/reference/joins), that Events have a `many_to_one`
258+
relation to Sessions, and specify a condition, such as all users' events from
259+
session start (inclusive) till the start of the next session (exclusive) belong
260+
to that session.
260261

261262
```javascript
262263
cube('Events', {
@@ -265,7 +266,7 @@ cube('Events', {
265266
// Add the joins block to the Events cube
266267
joins: {
267268
Sessions: {
268-
relationship: `belongsTo`,
269+
relationship: `many_to_one`,
269270
sql: `
270271
${Events.anonymousId} = ${Sessions.anonymousId}
271272
AND ${Events.timestamp} >= ${Sessions.startAt}
@@ -382,7 +383,7 @@ cube('Sessions', {
382383
// Declare this joins block in the Sessions cube
383384
joins: {
384385
Identifies: {
385-
relationship: `belongsTo`,
386+
relationship: `many_to_one`,
386387
sql: `${Identifies.anonymousId} = ${Sessions.anonymousId}`
387388
}
388389
},

docs/content/Examples-Tutorials-Recipes/Recipes/funnels.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ steps: [
264264

265265
In order to provide additional dimensions, funnels can be joined with other
266266
cubes using `user_id` at the first step of a funnel. This will always use a
267-
`belongsTo` relationship, so hence you should always join with the corresponding
267+
`many_to_one` relationship, hence you should always join with the corresponding
268268
user cube. Here, by 'user' we understand this to be any entity that can go
269269
through a sequence of steps within funnel. It could be a real web user with an
270270
auto assigned ID or a specific email sent by an email automation that goes
@@ -276,7 +276,7 @@ following:
276276
cube(`PurchaseFunnel`, {
277277
joins: {
278278
Users: {
279-
relationship: `belongsTo`,
279+
relationship: `many_to_one`,
280280
sql: `${CUBE}.first_step_user_id = ${Users.id}`,
281281
},
282282
},

docs/content/Schema/Advanced/Code-Reusability-Extending-Cubes.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cube(`BaseEvents`, {
4141

4242
joins: {
4343
Users: {
44-
relationship: `belongsTo`,
44+
relationship: `many_to_one`,
4545
sql: `${CUBE}.user_id = ${Users.id}`,
4646
},
4747
},

docs/content/Schema/Advanced/Polymorphic-Cubes.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ cube(`Lessons`, {
8989

9090
joins: {
9191
Students: {
92-
relationship: `belongsTo`,
92+
relationship: `many_to_one`,
9393
sql: `${CUBE}.student_id = ${Students.id}`,
9494
},
9595
Teachers: {
96-
relationship: `belongsTo`,
96+
relationship: `many_to_one`,
9797
sql: `${CUBE}.teacher_id = ${Teachers.id}`,
9898
},
9999
},

docs/content/Schema/Fundamentals/Additional-Concepts.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ cube(`Orders`, {
3434

3535
joins: {
3636
Users: {
37-
relationship: `belongsTo`,
37+
relationship: `many_to_one`,
3838
sql: `${CUBE}.user_id = ${Users.id}`,
3939
},
4040

4141
Products: {
42-
relationship: `belongsTo`,
42+
relationship: `many_to_one`,
4343
sql: `${CUBE}.product_id = ${Products.id}`,
4444
},
4545
},
@@ -76,10 +76,10 @@ cubes:
7676

7777
joins:
7878
- name: Users
79-
relationship: belongs_to
79+
relationship: many_to_one
8080
sql: "{CUBE}.user_id = {Users}.id"
8181
- name: Products
82-
relationship: belongs_to
82+
relationship: many_to_one
8383
sql: "{CUBE}.product_id = {Products}.id"
8484

8585
measures:
@@ -175,7 +175,7 @@ cube(`SalesManagers`, {
175175

176176
joins: {
177177
Deals: {
178-
relationship: `hasMany`,
178+
relationship: `one_to_many`,
179179
sql: `${CUBE}.id = ${Deals.salesManagerId}`,
180180
},
181181
},
@@ -218,7 +218,7 @@ cubes:
218218

219219
joins:
220220
- name: Deals
221-
relationship: has_many
221+
relationship: one_to_many
222222
sql: "{SalesManagers}.id = {Deals}.sales_manager_id"
223223

224224
measures:

docs/content/Schema/Fundamentals/Concepts.mdx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ cube('Orders', {
331331
332332
joins: {
333333
LineItems: {
334-
relationship: `belongsTo`,
334+
relationship: `many_to_one`,
335335
// Here we use the `CUBE` global to refer to the current cube,
336336
// so the following is equivalent to `Orders.id = LineItems.order_id`
337337
sql: `${CUBE}.id = ${LineItems.order_id}`,
@@ -348,19 +348,13 @@ cubes:
348348
# Here we use the `CUBE` global to refer to the current cube,
349349
# so the following is equivalent to `Orders.id = LineItems.order_id`
350350
sql: "{CUBE}.id = {LineItems.order_id}"
351-
relationship: belongs_to
351+
relationship: many_to_one
352352
```
353353
354354
</CodeTabs>
355355
356-
There are three kinds of join relationships:
357-
358-
- `belongsTo`/`belongs_to`
359-
- `hasOne`/`has_one`
360-
- `hasMany`/`has_many`
361-
362-
More information can be found in the [Joins reference
363-
documentation][ref-schema-ref-joins-types].
356+
There are the three [types of join relationships][ref-schema-ref-joins-types]:
357+
`one_to_one`, `one_to_many`, and `many_to_one`.
364358

365359
## Segments
366360

0 commit comments

Comments
 (0)