David
David

Reputation: 1650

In Realm, is there a way to query objects based on the content of an array of sub-objects they contain?

I have an object which has a realm array within it.

To use an example they use in their docs:

@interface Person : RLMObject
// ... other property declarations
@property RLMArray<Dog *><Dog> *dogs;
@end

So I would like to know the proper way to say "Give me all person objects which own a dog named fido"? I can't seem to find a way without making a back linking or writing a for loop. Is there a clean solution to this type of query in Realm?

Upvotes: 1

Views: 665

Answers (1)

bdash
bdash

Reputation: 18308

The query you're after would be expressed as:

[Person objectsWhere:@"ANY dogs.name == 'fido'"]

The ANY / ALL / NONE modifiers describe how many members of the array must match the subpredicate in order for the predicate to be treated as a match.

Upvotes: 1

Related Questions