Skip to content

Commit

Permalink
Support for querying objects' RLMArray properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kneth committed Jul 21, 2014
1 parent a3bd52b commit c6d2c5c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Realm/RLMQueryUtil.mm
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void update_query_with_value_expression(RLMObjectSchema *desc, tightdb::Query &q
// and loop through the elements of arr to build up link query
if ([arr count] == 2) {
isLinkQuery = YES;
if (firstProp.type != RLMPropertyTypeObject) {
if (firstProp.type != RLMPropertyTypeObject && firstProp.type != RLMPropertyTypeArray) {
throw RLMPredicateException(@"Invalid value", [NSString stringWithFormat:@"column name '%@' is not a link", firstColumnName]);
}
TableRef secondTable = query.get_table()->get_link_target(size_t(firstIndex));
Expand Down
40 changes: 40 additions & 0 deletions Realm/Tests/LinkTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,46 @@ - (void)testLinkQueryAllTypes
XCTAssertThrows([realm objects:@"LinkToAllTypesObject" where:@"allTypesCol.binaryCol = 'a'"], @"Binary data not supported");
}

- (void)testLinkQueryMany
{
RLMRealm *realm = [self realmWithTestPath];

ArrayPropertyObject *arrPropObj1 = [[ArrayPropertyObject alloc] init];
arrPropObj1.name = @"Test";
for(NSUInteger i=0; i<10; i++) {
StringObject *sobj = [[StringObject alloc] init];
sobj.stringCol = [NSString stringWithFormat:@"%lu", i];
[arrPropObj1.array addObject:sobj];
IntObject *iobj = [[IntObject alloc] init];
iobj.intCol = (int)i;
[arrPropObj1.intArray addObject:iobj];
}
[realm beginWriteTransaction];
[realm addObject:arrPropObj1];
[realm commitWriteTransaction];

XCTAssertEqual([[realm objects:[ArrayPropertyObject className] where:@"intArray.intCol > 10"] count], (NSUInteger)0, @"0 expected");
XCTAssertEqual([[realm objects:[ArrayPropertyObject className] where:@"intArray.intCol > 5"] count], (NSUInteger)1, @"1 expected");
XCTAssertEqual([[realm objects:[ArrayPropertyObject className] where:@"array.stringCol = '1'"] count], (NSUInteger)1, @"1 expected");

ArrayPropertyObject *arrPropObj2 = [[ArrayPropertyObject alloc] init];
arrPropObj2.name = @"Test";
for(NSUInteger i=0; i<4; i++) {
StringObject *sobj = [[StringObject alloc] init];
sobj.stringCol = [NSString stringWithFormat:@"%lu", i];
[arrPropObj2.array addObject:sobj];
IntObject *iobj = [[IntObject alloc] init];
iobj.intCol = (int)i;
[arrPropObj2.intArray addObject:iobj];
}
[realm beginWriteTransaction];
[realm addObject:arrPropObj2];
[realm commitWriteTransaction];
XCTAssertEqual([[realm objects:[ArrayPropertyObject className] where:@"intArray.intCol > 10"] count], (NSUInteger)0, @"0 expected");
XCTAssertEqual([[realm objects:[ArrayPropertyObject className] where:@"intArray.intCol > 5"] count], (NSUInteger)1, @"1 expected");
XCTAssertEqual([[realm objects:[ArrayPropertyObject className] where:@"intArray.intCol > 2"] count], (NSUInteger)2, @"2 expected");
}

// FIXME - disabled until we fix commit log issue which break transacions when leaking realm objects
/*
- (void)testCircularLinks
Expand Down

0 comments on commit c6d2c5c

Please sign in to comment.