Skip to content

Commit 860ae33

Browse files
committed
generator comments for top-level code; test fix
1 parent de00a7a commit 860ae33

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

generator/integration-tests/common.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ commonModelTests(ModelDefinition defs, ModelInfo jsonModel) {
2424
..addAll(entity.properties.map((prop) => prop.id.uid))
2525
..addAll(entity.properties
2626
.where((prop) => prop.hasIndexFlag())
27-
.map((prop) => prop.id.uid))
27+
.map((prop) => prop.indexId!.uid))
2828
..addAll(entity.relations.map((rel) => rel.id.uid)))
2929
.reduce((List<int> a, List<int> b) => a + b);
3030

@@ -69,19 +69,17 @@ commonModelTests(ModelDefinition defs, ModelInfo jsonModel) {
6969
defs.model.entities
7070
.map((ModelEntity e) => e.properties
7171
.where((p) => p.hasIndexFlag())
72-
.map((el) => el.id)
72+
.map((p) => p.indexId!)
7373
.toList())
7474
.reduce((List<IdUid> a, List<IdUid> b) => a + b),
7575
jsonModel.retiredIndexUids);
76-
testLastId(defs.model.lastIndexId, defs.model.entities.map((el) => el.id),
77-
jsonModel.retiredIndexUids);
7876
});
7977

8078
test('lastRelationId', () {
8179
testLastId(
8280
defs.model.lastRelationId,
8381
defs.model.entities
84-
.map((ModelEntity e) => e.relations.map((el) => el.id).toList())
82+
.map((ModelEntity e) => e.relations.map((r) => r.id).toList())
8583
.reduce((List<IdUid> a, List<IdUid> b) => a + b),
8684
jsonModel.retiredRelationUids);
8785
});

generator/lib/src/code_chunks.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:convert';
2-
31
import 'package:build/build.dart';
42
import 'package:collection/collection.dart' show IterableExtension;
53
import 'package:objectbox/internal.dart';
@@ -26,6 +24,7 @@ class CodeChunks {
2624
${model.entities.map(createModelEntity).join(',')}
2725
];
2826
27+
/// ObjectBox model definition, pass it to [Store] - Store(getObjectBoxModel())
2928
ModelDefinition getObjectBoxModel() {
3029
${defineModel(model)}
3130
@@ -36,7 +35,7 @@ class CodeChunks {
3635
return ModelDefinition(model, bindings);
3736
}
3837
39-
${model.entities.mapIndexed((i, entity) => "class ${entity.name}_ {${_queryConditionBuilder(i, entity)}}").join("\n")}
38+
${model.entities.mapIndexed(_metaClass).join("\n")}
4039
""";
4140

4241
static List<T> sorted<T>(List<T> list) {
@@ -490,8 +489,8 @@ class CodeChunks {
490489
.join(',') +
491490
'}';
492491

493-
static String _queryConditionBuilder(int i, ModelEntity entity) {
494-
final ret = <String>[];
492+
static String _metaClass(int i, ModelEntity entity) {
493+
final fields = <String>[];
495494
for (var p = 0; p < entity.properties.length; p++) {
496495
final prop = entity.properties[p];
497496
final name = prop.name;
@@ -536,16 +535,20 @@ class CodeChunks {
536535
'static final ${propertyFieldName(prop)} = Query${fieldType}Property<${entity.name}';
537536
if (prop.isRelation) propCode += ', ${prop.relationTarget}';
538537
propCode += '>(_entities[$i].properties[$p]);';
539-
ret.add(propCode);
538+
fields.add(propCode);
540539
}
541540

542541
for (var r = 0; r < entity.relations.length; r++) {
543542
final rel = entity.relations[r];
544543
final targetEntityName =
545544
entity.model.findEntityByUid(rel.targetId.uid)!.name;
546-
ret.add('static final ${rel.name} = QueryRelationMany'
545+
fields.add('static final ${rel.name} = QueryRelationMany'
547546
'<${entity.name}, $targetEntityName>(_entities[$i].relations[$r]);');
548547
}
549-
return ret.join();
548+
549+
return '''
550+
/// [${entity.name}] entity fields to define ObjectBox queries.
551+
class ${entity.name}_ {${fields.join()}}
552+
''';
550553
}
551554
}

0 commit comments

Comments
 (0)