Skip to content

Commit

Permalink
Tests: add simple regular + link condition query tests for ToOne.
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot-team committed Sep 5, 2023
1 parent 9fcce55 commit f45dc83
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions objectbox_test/test/relations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void main() {
env.box.putMany([src1, src2]);

{
// find with condition on related entity
final qb = env.box.query();
qb.link(TestEntity_.relA, RelatedEntityA_.tInt.equals(10));
final query = qb.build();
Expand All @@ -145,6 +146,7 @@ void main() {
}

{
// find with condition on a nested related entity
final qb = env.box.query();
qb
.link(TestEntity_.relA)
Expand All @@ -156,6 +158,41 @@ void main() {
query.close();
}
});

test('query link with regular conditions', () {
final a1 = RelatedEntityA(tInt: 1);
final apples1 = TestEntity(tString: 'Apples');
apples1.relA.target = a1;
final oranges1 = TestEntity(tString: 'Oranges');
oranges1.relA.target = a1;
final a2 = RelatedEntityA(tInt: 2);
final apples2 = TestEntity(tString: 'Apples');
apples2.relA.target = a2;
final bananas2 = TestEntity(tString: 'Bananas');
bananas2.relA.target = a2;
env.box.putMany([apples1, oranges1, apples2, bananas2]);

{
// link condition matches orders from 2
// simple regular condition matches single order for both
final qb = env.box.query(TestEntity_.tString.equals("Apples"));
qb.link(TestEntity_.relA, RelatedEntityA_.tInt.equals(2));
final query = qb.build();
expect(query.find().length, 1);
query.close();
}

{
// link condition matches orders from 2
// complex regular conditions matches two orders for 1, one for 2
final qb = env.box.query(TestEntity_.tString.equals("Apples") |
TestEntity_.tString.equals("Oranges"));
qb.link(TestEntity_.relA, RelatedEntityA_.tInt.equals(2));
final query = qb.build();
expect(query.find().length, 1);
query.close();
}
});
});

group('ToMany list management', () {
Expand Down

0 comments on commit f45dc83

Please sign in to comment.