Skip to content

Commit

Permalink
Add testEmbeddedObjectQuery (realm#6729)
Browse files Browse the repository at this point in the history
* Add testEmbeddedObjectQuery
  • Loading branch information
ejm01 committed Oct 7, 2020
1 parent 78f07c8 commit 9663004
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Realm/Tests/QueryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,38 @@ - (void)verifySort:(RLMRealm *)realm column:(NSString *)column ascending:(BOOL)a
XCTAssertEqualObjects(obj[column], val, @"%@", column);
}

- (void)testEmbeddedObjectQuery {
RLMRealm *realm = [self realm];
[realm beginWriteTransaction];
EmbeddedIntParentObject *obj0 = [EmbeddedIntParentObject createInRealm:realm withValue:@[@1, @[@2], @[@[@3]]]];
EmbeddedIntParentObject *obj1 = [EmbeddedIntParentObject createInRealm:realm withValue:@[@4, @[@5], @[@[@6]]]];
EmbeddedIntParentObject *obj2 = [EmbeddedIntParentObject createInRealm:realm withValue:@[@7, @[@8], @[@[@9]]]];
[realm commitWriteTransaction];

// Query parent objects based on property of embedded object
RLMResults *r0 = [EmbeddedIntParentObject objectsWhere:@"object.intCol = 2"];
XCTAssertEqualObjects(r0[0], obj0);
XCTAssert(r0.count == 1);

// Query parent objects based on array of embedded objects
RLMResults *r1 = [EmbeddedIntParentObject objectsWhere:@"ANY array.intCol > 4"];
XCTAssertEqualObjects(r1[0], obj1);
XCTAssertEqualObjects(r1[1], obj2);
XCTAssert(r1.count == 2);

// Compound query using two different embedded object properties
RLMResults *r2 = [EmbeddedIntParentObject objectsWhere:@"ANY array.intCol > 4 and object.intCol = 5"];
XCTAssertEqualObjects(r2[0], obj1);
XCTAssert(r2.count == 1);

// Aggregate query on embedded object array, sort using embedded object key path
RLMResults *r3 = [[EmbeddedIntParentObject objectsWhere:@"array.@max.intCol < 9"]
sortedResultsUsingKeyPath:@"object.intCol" ascending:NO];
XCTAssertEqualObjects(r3[0], obj1);
XCTAssertEqualObjects(r3[1], obj0);
XCTAssert(r3.count == 2);
}

- (void)testQuerySorting
{
RLMRealm *realm = [self realm];
Expand Down

0 comments on commit 9663004

Please sign in to comment.