Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
Multiple 'belongsTo' joins in a cube in Cube.js

There are three cubes that I need to create, namely, "Order", "OrderItem" and "Adjustment". Adjustments can belong to Order or OrderItem (not to both at the same time).

Order -> Adjustment is a one-to-many relationship and therefore Order has "hasMany" join with Adjustment.

OrderItem -> Adjustment is also a one-to-many relationship and so OrderItem has "hasMany" join with Adjustment.

Now, how do I model the Adjustment cube? Can it have two joins of the "belongsTo" kind like the following:

 cube('Adjustments', {
  sql: `SELECT * FROM "orders-parquet-${ENVIRONMENT}".order_adjustments`,

  joins: {
    Orders: {
      relationship: 'belongsTo',
      sql: `${Orders}.order_id = ${Adjustments}.order_id`,
    },
    OrderItems: {
      relationship: 'belongsTo',
      sql: `${OrderItems}.order_item_id = ${Adjustments}.order_item_id`,
    },
  },

Is this the proper way to model the cubes? I googled but could not find any example where two "belongsTo" joins were used in one cube.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!