@@ -92,7 +92,7 @@ class Dart extends LanguageMeta {
9292 }); -%>
9393<% const __attrs = strict ? sortedAttributes : collection.attributes; -%>
9494<% for (const attribute of __attrs ) { -%>
95- <% if (attribute.type === ' relationship ' ) { -%>
95+ <% if (attribute.type === ' ${AttributeType.RELATIONSHIP} ' ) { -%>
9696<% const related = collections.find(c => c.$id === attribute.relatedCollection); -%>
9797<% if (related && ! __relatedImportsSeen .has(toSnakeCase(related.name))) { -%>
9898import '<% - toSnakeCase(related.name) %> .dart';
@@ -102,7 +102,7 @@ import '<%- toSnakeCase(related.name) %>.dart';
102102<% } -%>
103103
104104<% for (const attribute of __attrs ) { -%>
105- <% if (attribute.format === ' enum ' ) { -%>
105+ <% if (attribute.format === ' ${AttributeType.ENUM} ' ) { -%>
106106enum <% - toPascalCase(attribute.key) %> {
107107<% for (const [index, element] of Object .entries(attribute.elements)) { -%>
108108 <% - strict ? toCamelCase(element) : element %><% if (index < attribute.elements.length - 1 ) { -%> ,<% } %>
@@ -125,8 +125,8 @@ class <%= toPascalCase(collection.name) %> {
125125 factory <%= toPascalCase(collection.name) %> .fromMap(Map<String , dynamic > map) {
126126 return <%= toPascalCase(collection.name) %> (
127127<% for (const [index, attribute] of Object .entries(__attrs )) { -%>
128- <%= strict ? toCamelCase(attribute.key) : attribute.key %> : <% if (attribute.type === ' string ' || attribute.type === ' email ' || attribute.type === ' datetime ' ) { -%>
129- <% if (attribute.format === ' enum ' ) { -%>
128+ <%= strict ? toCamelCase(attribute.key) : attribute.key %> : <% if (attribute.type === ' ${AttributeType.STRING} ' || attribute.type === ' ${AttributeType.EMAIL} ' || attribute.type === ' ${AttributeType.DATETIME} ' ) { -%>
129+ <% if (attribute.format === ' ${AttributeType.ENUM} ' ) { -%>
130130<% if (attribute.array) { -%>
131131(map['<%= attribute.key %> '] as List<dynamic >?)?.map((e) => <% - toPascalCase(attribute.key) %> .values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
132132<% if (!attribute.required) { -%>
@@ -138,19 +138,19 @@ map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.
138138List<String >.from(map['<%= attribute.key %> '] ?? [])<% } else { -%>
139139map['<%= attribute.key %> ']<% if (!attribute.required) { %> ?<% } %> .toString()<% } -%>
140140<% } -%>
141- <% } else if (attribute.type === ' integer ' ) { -%>
141+ <% } else if (attribute.type === ' ${AttributeType.INTEGER} ' ) { -%>
142142<% if (attribute.array) { -%>
143143List<int >.from(map['<%= attribute.key %> '] ?? [])<% } else { -%>
144144map['<%= attribute.key %> ']<% } -%>
145- <% } else if (attribute.type === ' double ' ) { -%>
145+ <% } else if (attribute.type === ' ${AttributeType.FLOAT} ' ) { -%>
146146<% if (attribute.array) { -%>
147147List<double >.from(map['<%= attribute.key %> '] ?? [])<% } else { -%>
148148map['<%= attribute.key %> ']<% } -%>
149- <% } else if (attribute.type === ' boolean ' ) { -%>
149+ <% } else if (attribute.type === ' ${AttributeType.BOOLEAN} ' ) { -%>
150150<% if (attribute.array) { -%>
151151List<bool >.from(map['<%= attribute.key %> '] ?? [])<% } else { -%>
152152map['<%= attribute.key %> ']<% } -%>
153- <% } else if (attribute.type === ' relationship ' ) { -%>
153+ <% } else if (attribute.type === ' ${AttributeType.RELATIONSHIP} ' ) { -%>
154154<% if ((attribute.relationType === ' oneToMany' && attribute.side === ' parent' ) || (attribute.relationType === ' manyToOne' && attribute.side === ' child' ) || attribute.relationType === ' manyToMany' ) { -%>
155155(map['<%= attribute.key %> '] as List<dynamic >?)?.map((e) => <% - toPascalCase(collections.find(c => c.$id === attribute.relatedCollection).name) %> .fromMap(e)).toList()
156156<% } else { -%>
@@ -166,12 +166,12 @@ map['<%= attribute.key %>'] != null ? <%- toPascalCase(collections.find(c => c.$
166166 Map<String , dynamic > toMap() {
167167 return {
168168<% for (const [index, attribute] of Object .entries(__attrs )) { -%>
169- '<%= attribute.key %> ': <% if (attribute.type === ' relationship ' ) { -%>
169+ '<%= attribute.key %> ': <% if (attribute.type === ' ${AttributeType.RELATIONSHIP} ' ) { -%>
170170<% if ((attribute.relationType === ' oneToMany' && attribute.side === ' parent' ) || (attribute.relationType === ' manyToOne' && attribute.side === ' child' ) || attribute.relationType === ' manyToMany' ) { -%>
171171<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %> ?<% } %> .map((e) => e.toMap()).toList()
172172<% } else { -%>
173173<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %> ?<% } %> .toMap()<% } -%>
174- <% } else if (attribute.format === ' enum ' ) { -%>
174+ <% } else if (attribute.format === ' ${AttributeType.ENUM} ' ) { -%>
175175<% if (attribute.array) { -%>
176176<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %> ?<% } %> .map((e) => e.name).toList()<% } else { -%>
177177<%= strict ? toCamelCase(attribute.key) : attribute.key %><% if (!attribute.required) { %> ?<% } %> .name<% } -%>
0 commit comments