Skip to content

Commit 68cd1c9

Browse files
external types: add ToMany and external name to test entity #139
1 parent 04fa1ca commit 68cd1c9

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

objectbox_test/test/box_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,19 @@ void main() {
725725
});
726726

727727
test('@ExternalType and @ExternalName annotations work correctly', () {
728+
// That the database accepts a model with external types and names is tested
729+
// implicitly by creating a Store. This test is only a smoke test to verify
730+
// the annotated properties and ToMany work without issue.
728731
final box = store.box<EntityWithExternalType>();
729-
final id = box.put(EntityWithExternalType([90, 100, 110], [1, 2, 3]));
732+
var testObject = EntityWithExternalType([90, 100, 110], [1, 2, 3]);
733+
testObject.mongoIdEntities
734+
.add(EntityWithExternalType([120, 130, 140], null));
735+
final id = box.put(testObject);
730736
final item = box.get(id)!;
731737
expect(item.id, id);
732738
expect(item.mongoId, [90, 100, 110]);
733739
expect(item.mongoUuid, [1, 2, 3]);
740+
expect(item.mongoIdEntities.first.mongoId, [120, 130, 140]);
734741
});
735742

736743
test('.count() works', () {

objectbox_test/test/entity.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ class HnswObject {
473473
}
474474

475475
@Entity()
476+
@ExternalName(name: 'my-mongo-entity')
476477
class EntityWithExternalType {
477478
@Id()
478479
int id = 0;
@@ -485,6 +486,10 @@ class EntityWithExternalType {
485486
@ExternalName(name: 'my-mongo-uuid')
486487
List<int>? mongoUuid;
487488

489+
@ExternalType(type: ExternalPropertyType.mongoIdVector)
490+
@ExternalName(name: 'my-mongo-rel')
491+
final mongoIdEntities = ToMany<EntityWithExternalType>();
492+
488493
EntityWithExternalType(this.mongoId, this.mongoUuid);
489494
}
490495

objectbox_test/test/objectbox-model.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,20 @@
747747
"type": 27
748748
}
749749
],
750-
"relations": []
750+
"relations": [
751+
{
752+
"id": "2:313640065593441165",
753+
"name": "mongoIdEntities",
754+
"targetId": "16:5931645853908059165",
755+
"externalType": 124,
756+
"externalName": "my-mongo-rel"
757+
}
758+
]
751759
}
752760
],
753761
"lastEntityId": "16:5931645853908059165",
754762
"lastIndexId": "23:6649884639373473085",
755-
"lastRelationId": "1:2155747579134420981",
763+
"lastRelationId": "2:313640065593441165",
756764
"lastSequenceId": "0:0",
757765
"modelVersion": 5,
758766
"modelVersionParserMinimum": 5,

0 commit comments

Comments
 (0)