Skip to content

Commit f45dc83

Browse files
Tests: add simple regular + link condition query tests for ToOne.
1 parent 9fcce55 commit f45dc83

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

objectbox_test/test/relations_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void main() {
135135
env.box.putMany([src1, src2]);
136136

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

147148
{
149+
// find with condition on a nested related entity
148150
final qb = env.box.query();
149151
qb
150152
.link(TestEntity_.relA)
@@ -156,6 +158,41 @@ void main() {
156158
query.close();
157159
}
158160
});
161+
162+
test('query link with regular conditions', () {
163+
final a1 = RelatedEntityA(tInt: 1);
164+
final apples1 = TestEntity(tString: 'Apples');
165+
apples1.relA.target = a1;
166+
final oranges1 = TestEntity(tString: 'Oranges');
167+
oranges1.relA.target = a1;
168+
final a2 = RelatedEntityA(tInt: 2);
169+
final apples2 = TestEntity(tString: 'Apples');
170+
apples2.relA.target = a2;
171+
final bananas2 = TestEntity(tString: 'Bananas');
172+
bananas2.relA.target = a2;
173+
env.box.putMany([apples1, oranges1, apples2, bananas2]);
174+
175+
{
176+
// link condition matches orders from 2
177+
// simple regular condition matches single order for both
178+
final qb = env.box.query(TestEntity_.tString.equals("Apples"));
179+
qb.link(TestEntity_.relA, RelatedEntityA_.tInt.equals(2));
180+
final query = qb.build();
181+
expect(query.find().length, 1);
182+
query.close();
183+
}
184+
185+
{
186+
// link condition matches orders from 2
187+
// complex regular conditions matches two orders for 1, one for 2
188+
final qb = env.box.query(TestEntity_.tString.equals("Apples") |
189+
TestEntity_.tString.equals("Oranges"));
190+
qb.link(TestEntity_.relA, RelatedEntityA_.tInt.equals(2));
191+
final query = qb.build();
192+
expect(query.find().length, 1);
193+
query.close();
194+
}
195+
});
159196
});
160197

161198
group('ToMany list management', () {

0 commit comments

Comments
 (0)