cube-js / cube-js/cube

How to join same table twice ?

Open
#3,692 8 comments 1 reaction 1 assignee Claimed by @ivan-vdovin View on GitHub
help wanted
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Problem**

Want to join same table twice, but the key must be the cube name

**Related Cube.js schema**
```javascript
// how to avoid this ?
cube(`CalleeUsers`, {
extends: Users,
});

cube(`PhoneCallEvents`, {
sql: `SELECT * FROM public.phone_call_events`,
joins: {
// want to use the key as CallerUser, but CallerUser cube not exists
Users: {
toCude: Users, // maybe support specify the target cube in here ?
relationship: `belongsTo`,
sql: `${PhoneCallEvents}.caller_object_id = ${Users}.id`,
},
// above cube make this work
CalleeUsers: {
relationship: `belongsTo`,
sql: `${PhoneCallEvents}.callee_object_id = ${CalleeUsers}.id`,
},
},
}
)
```

New to cubejs, don't know if there is a way to handle join same table twice.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.