Skip to content

Commit 89c7c8e

Browse files
committed
fix: relatedCollection name
1 parent c729a6c commit 89c7c8e

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

templates/cli/lib/commands/types.js.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
129129
} else {
130130
for (const collection of collections) {
131131
const content = templater({
132+
collections,
132133
collection,
133134
strict,
134135
path: rawOutputDirectory ?? '',

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Dart extends LanguageMeta {
8686
getTemplate() {
8787
return `<% for (const attribute of collection.attributes) { -%>
8888
<% if (attribute.type === 'relationship') { -%>
89-
import '<%- toSnakeCase(attribute.relatedCollection) %>.dart';
89+
import '<%- toSnakeCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.dart';
9090

9191
<% } -%>
9292
<% } -%>
@@ -153,11 +153,11 @@ map['<%= attribute.key %>']<% if (!attribute.required) { %> ?? null<% } -%>
153153
<% } -%>
154154
<% } else if (attribute.type === 'relationship') { -%>
155155
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
156-
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.relatedCollection) %>.fromMap(e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
156+
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.fromMap(e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
157157
<% } else { -%>
158158
<% if (!attribute.required) { -%>
159-
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.relatedCollection) %>.fromMap(map['<%= attribute.key %>']) : null<% } else { -%>
160-
<%- toPascalCase(attribute.relatedCollection) %>.fromMap(map['<%= attribute.key %>'])<% } -%>
159+
map['<%= attribute.key %>'] != null ? <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.fromMap(map['<%= attribute.key %>']) : null<% } else { -%>
160+
<%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>.fromMap(map['<%= attribute.key %>'])<% } -%>
161161
<% } -%>
162162
<% } -%><% if (index < collection.attributes.length - 1) { %>,<% } %>
163163
<% } -%>

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

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

55
class Java extends LanguageMeta {
6-
getType(attribute) {
6+
getType(attribute, collections) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
@@ -24,7 +24,8 @@ class Java extends LanguageMeta {
2424
type = "boolean";
2525
break;
2626
case AttributeType.RELATIONSHIP:
27-
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
27+
const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
28+
type = LanguageMeta.toPascalCase(relatedCollection.name);
2829
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
2930
type = "List<" + type + ">";
3031
}
@@ -53,7 +54,7 @@ class Java extends LanguageMeta {
5354
import java.util.Objects;
5455
<% for (const attribute of collection.attributes) { -%>
5556
<% if (attribute.type === 'relationship') { -%>
56-
import io.appwrite.models.<%- toPascalCase(attribute.relatedCollection) %>;
57+
import io.appwrite.models.<%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>;
5758

5859
<% } -%>
5960
<% } -%>
@@ -70,15 +71,15 @@ public class <%- toPascalCase(collection.name) %> {
7071
<% } -%>
7172
<% } -%>
7273
<% for (const attribute of collection.attributes) { -%>
73-
private <%- getType(attribute) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
74+
private <%- getType(attribute, collections) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
7475
<% } -%>
7576

7677
public <%- toPascalCase(collection.name) %>() {
7778
}
7879

7980
public <%- toPascalCase(collection.name) %>(
8081
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
81-
<%- getType(attribute) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
82+
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
8283
<% } -%>
8384
) {
8485
<% for (const attribute of collection.attributes) { -%>
@@ -87,11 +88,11 @@ public class <%- toPascalCase(collection.name) %> {
8788
}
8889

8990
<% for (const attribute of collection.attributes) { -%>
90-
public <%- getType(attribute) %> get<%- toPascalCase(attribute.key) %>() {
91+
public <%- getType(attribute, collections) %> get<%- toPascalCase(attribute.key) %>() {
9192
return <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
9293
}
9394

94-
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
95+
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
9596
this.<%= strict ? toCamelCase(attribute.key) : attribute.key %> = <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
9697
}
9798

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Kotlin extends LanguageMeta {
5151

5252
<% for (const attribute of collection.attributes) { -%>
5353
<% if (attribute.type === 'relationship') { -%>
54-
import <%- toPascalCase(attribute.relatedCollection) %>
54+
import <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>
5555

5656
<% } -%>
5757
<% } -%>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace Appwrite\\Models;
5555
5656
<% for (const attribute of collection.attributes) { -%>
5757
<% if (attribute.type === 'relationship' && !(attribute.relationType === 'manyToMany') && !(attribute.relationType === 'oneToMany' && attribute.side === 'parent')) { -%>
58-
use Appwrite\\Models\\<%- toPascalCase(attribute.relatedCollection) %>;
58+
use Appwrite\\Models\\<%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>;
5959
6060
<% } -%>
6161
<% } -%>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {
125125
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
126126
<% if (attribute.type === 'relationship') { -%>
127127
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
128-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [<%- toPascalCase(attribute.relatedCollection) %>]<% if (index < collection.attributes.length - 1) { %>,<% } %>
128+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [<%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %>]<% if (index < collection.attributes.length - 1) { %>,<% } %>
129129
<% } else { -%>
130-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(attribute.relatedCollection) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
130+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
131131
<% } -%>
132132
<% } else if (attribute.array) { -%>
133133
<% if (attribute.type === 'string') { -%>

0 commit comments

Comments
 (0)