Skip to content

Commit 892cba9

Browse files
committed
name fix
1 parent c9060f5 commit 892cba9

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CubeMembers, SchemaContext } from '../ScaffoldingTemplate';
33
import {
44
CubeDescriptor,
55
DatabaseSchema,
6+
Dimension,
67
MemberType,
78
ScaffoldingSchema,
89
TableName,
@@ -103,7 +104,7 @@ export abstract class BaseSchemaFormatter {
103104
: undefined;
104105
}
105106

106-
protected memberName(member) {
107+
protected memberName(member: { title: string }) {
107108
const title = member.title.replace(/[^A-Za-z0-9]+/g, '_').toLowerCase();
108109

109110
if (this.options.snakeCase) {
@@ -156,12 +157,12 @@ export abstract class BaseSchemaFormatter {
156157
const joins = tableSchema.joins
157158
.map((j) => {
158159
const thisTableColumnRef = j.thisTableColumnIncludedAsDimension
159-
? this.cubeReference(`CUBE.${j.thisTableColumn}`)
160+
? this.cubeReference(`CUBE.${this.memberName({ title: j.thisTableColumn })}`)
160161
: `${this.cubeReference('CUBE')}.${this.escapeName(
161162
j.thisTableColumn
162163
)}`;
163164
const columnToJoinRef = j.columnToJoinIncludedAsDimension
164-
? this.cubeReference(`${j.cubeToJoin}.${j.columnToJoin}`)
165+
? this.cubeReference(`${j.cubeToJoin}.${this.memberName({ title: j.columnToJoin })}`)
165166
: `${this.cubeReference(j.cubeToJoin)}.${this.escapeName(j.columnToJoin)}`;
166167

167168
return ({

packages/cubejs-schema-compiler/test/unit/__snapshots__/scaffolding-template.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ exports[`ScaffoldingTemplate JavaScript formatter uses dimension refs instead of
426426
},
427427
428428
customerkey: {
429-
sql: \`customerkey\`,
429+
sql: \`\${CUBE}.\\"customerKey\\"\`,
430430
type: \`string\`
431431
}
432432
},
@@ -674,7 +674,7 @@ exports[`ScaffoldingTemplate Yaml formatter uses dimension refs instead of table
674674
primary_key: true
675675
676676
- name: customerkey
677-
sql: customerkey
677+
sql: \\"{CUBE}.\\\\\\"customerKey\\\\\\"\\"
678678
type: string
679679
680680
measures:

packages/cubejs-schema-compiler/test/unit/scaffolding-template.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const schemasWithPrimaryAndForeignKeys = {
110110
attributes: []
111111
},
112112
{
113-
name: 'customerkey',
113+
name: 'customerKey',
114114
type: 'string',
115115
attributes: [],
116116
foreign_keys: [

packages/cubejs-schema-compiler/test/unit/utils.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { camelizeCube } from '../../src/compiler/utils';
2+
import { toSnakeCase } from '../../src/scaffolding/utils';
23

34
describe('Test Utils', () => {
5+
it('toSnakeCase', () => {
6+
expect(toSnakeCase('customerkey')).toEqual('customerkey');
7+
expect(toSnakeCase('customerKey')).toEqual('customer_key');
8+
expect(toSnakeCase('customer_key')).toEqual('customer_key');
9+
});
10+
411
it('camelizeObject (js)', () => {
512
const res = camelizeCube({
613
sql_table: 'tbl',

0 commit comments

Comments
 (0)