Realm-cocoa: How to search result by two models

Created on 25 Mar 2017  路  2Comments  路  Source: realm/realm-cocoa

Hi, I create two classes like this
```@class Person;

@interface Dog : RLMObject

@property NSString *name;
@property NSString *owner;
@property NSInteger age;
@property NSDate *picture;

@end
RLM_ARRAY_TYPE(Dog) // define RLMArray

@interface Person : RLMObject

@property NSString *name;
@property NSDate *birthdate;
@property RLMArray *dogs;

@end
```

and I want to search result when person.name=Rex and Dog.name=Jack which like sql select * from Person as P join Dog as D where p.name = Rex and D.name = Jack

T-Help

Most helpful comment

@hanjt Realm doesn't have a concept of join in SQL. Instead, Realm has a native link that stores objects including relations. So you don't need join query for Realm. What you want can be achieved with the following query:

[Person objectsWhere:@"name = %@ and any dogs.name = %@", @"Rex", @"Jack"];

All 2 comments

@hanjt Realm doesn't have a concept of join in SQL. Instead, Realm has a native link that stores objects including relations. So you don't need join query for Realm. What you want can be achieved with the following query:

[Person objectsWhere:@"name = %@ and any dogs.name = %@", @"Rex", @"Jack"];

Hi @hanjt! I hope @kishikawakatsumi's answer was able to help you.

I'm going to close this issue now. Please feel free to re-open this issue if you have any follow-up. Thanks!

Was this page helpful?
0 / 5 - 0 ratings