Skip to content

Commit 943c507

Browse files
committed
fix: use collection name instead of id in case of relationships
1 parent 10c7154 commit 943c507

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

templates/cli/lib/type-generation/languages/typescript.js.twig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { AttributeType } = require('../attribute');
66
const { LanguageMeta } = require("./language");
77

88
class TypeScript extends LanguageMeta {
9-
getType(attribute) {
9+
getType(attribute, collections) {
1010
let type = ""
1111
switch (attribute.type) {
1212
case AttributeType.STRING:
@@ -29,7 +29,8 @@ class TypeScript extends LanguageMeta {
2929
type = "boolean";
3030
break;
3131
case AttributeType.RELATIONSHIP:
32-
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
32+
const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
33+
type = LanguageMeta.toPascalCase(relatedCollection.name);
3334
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
3435
type = `${type}[]`;
3536
}
@@ -86,7 +87,7 @@ export enum <%- toPascalCase(attribute.key) %> {
8687
<% for (const [index, collection] of Object.entries(collections)) { -%>
8788
export type <%- toPascalCase(collection.name) %> = Models.Document & {
8889
<% for (const attribute of collection.attributes) { -%>
89-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>;
90+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %>;
9091
<% } -%>
9192
}<% if (index < collections.length - 1) { %>
9293
<% } %>

0 commit comments

Comments
 (0)