Search code examples
cubecube.js

Cube Js | How to join two tables for measures and dimensions


I want to Join two tables which is User and Organizations. I don't know how to connect another table which is Organizations where i have to write query for that.

*cube(`Users`, {
  sql: `select * from users`,
  joins: {
    Organizations: {
      relationship: `belongsTo`,
      sql: `${Users}.organization_id = ${Organizations}.id`
   }
  },
  }
});*

Solution

  • You have to create another schema for your another table name like below

    cube(`Organizations`, {
       sql: `select * from organizations`,
       measures:{
          count: {
             type: `count`,
             drillMembers: [id]
          }
       },
    });
    

    You just simply creating a new schema and write the joins whatever columns you want. After that use can easily access in both dimensions and measures.