cube-js/cube

How to join same table twice ?

Open

#3,692 opened on Nov 17, 2021

View on GitHub
 (8 comments) (1 reaction) (1 assignee)Rust (1,965 forks)batch import
help wanted

Repository metrics

Stars
 (19,563 stars)
PR merge metrics
 (Avg merge 5d 16h) (138 merged PRs in 30d)

Description

Problem

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

Related Cube.js schema

// 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