Skip to content

Commit ad4e8e3

Browse files
committed
fix(schema-compiler): join relationship aliases
1 parent 3fbae30 commit ad4e8e3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/cubejs-schema-compiler/src/scaffolding/formatters/BaseSchemaFormatter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ import { toSnakeCase } from '../utils';
1313

1414
const JOIN_RELATIONSHIP_MAP = {
1515
hasOne: 'one_to_one',
16+
has_one: 'one_to_one',
1617
hasMany: 'one_to_many',
18+
has_many: 'one_to_many',
1719
belongsTo: 'many_to_one',
20+
belongs_to: 'many_to_one',
1821
};
1922

2023
export type SchemaFile = {
@@ -107,7 +110,7 @@ export abstract class BaseSchemaFormatter {
107110
let table = `${
108111
tableSchema.schema?.length ? `${this.escapeName(tableSchema.schema)}.` : ''
109112
}${this.escapeName(tableSchema.table)}`;
110-
113+
111114
if (this.options.catalog) {
112115
table = `${this.escapeName(this.options.catalog)}.${table}`;
113116
}
@@ -126,7 +129,7 @@ export abstract class BaseSchemaFormatter {
126129
: {
127130
sql: `SELECT * FROM ${table}`,
128131
};
129-
132+
130133
return {
131134
cube: tableSchema.cube,
132135
...sqlOption,
@@ -139,7 +142,7 @@ export abstract class BaseSchemaFormatter {
139142
j.thisTableColumn
140143
)} = ${this.cubeReference(j.cubeToJoin)}.${this.escapeName(j.columnToJoin)}`,
141144
relationship: this.options.snakeCase
142-
? JOIN_RELATIONSHIP_MAP[j.relationship]
145+
? (JOIN_RELATIONSHIP_MAP[j.relationship] ?? j.relationship)
143146
: j.relationship,
144147
},
145148
}))

0 commit comments

Comments
 (0)