@@ -3,7 +3,7 @@ const { AttributeType } = require('../attribute');
3
3
const { LanguageMeta } = require("./language");
4
4
5
5
class Java extends LanguageMeta {
6
- getType(attribute) {
6
+ getType(attribute, collections ) {
7
7
let type = "";
8
8
switch (attribute.type) {
9
9
case AttributeType.STRING:
@@ -24,7 +24,8 @@ class Java extends LanguageMeta {
24
24
type = "boolean";
25
25
break;
26
26
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);
28
29
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
29
30
type = "List< " + type + ">";
30
31
}
@@ -53,7 +54,7 @@ class Java extends LanguageMeta {
53
54
import java.util.Objects;
54
55
<% for (const attribute of collection.attributes) { -%>
55
56
<% 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 ) %> ;
57
58
58
59
<% } -%>
59
60
<% } -%>
@@ -70,15 +71,15 @@ public class <%- toPascalCase(collection.name) %> {
70
71
<% } -%>
71
72
<% } -%>
72
73
<% 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 %> ;
74
75
<% } -%>
75
76
76
77
public <% - toPascalCase(collection.name) %> () {
77
78
}
78
79
79
80
public <% - toPascalCase(collection.name) %> (
80
81
<% 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 ? ' ,' : ' ' %>
82
83
<% } -%>
83
84
) {
84
85
<% for (const attribute of collection.attributes) { -%>
@@ -87,11 +88,11 @@ public class <%- toPascalCase(collection.name) %> {
87
88
}
88
89
89
90
<% for (const attribute of collection.attributes) { -%>
90
- public <% - getType(attribute) %> get<% - toPascalCase(attribute.key) %> () {
91
+ public <% - getType(attribute, collections ) %> get<% - toPascalCase(attribute.key) %> () {
91
92
return <%= strict ? toCamelCase(attribute.key) : attribute.key %> ;
92
93
}
93
94
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 %> ) {
95
96
this.<%= strict ? toCamelCase(attribute.key) : attribute.key %> = <%= strict ? toCamelCase(attribute.key) : attribute.key %> ;
96
97
}
97
98
0 commit comments