I have a Realm object called Restaurantin my app. This Restaurant object has lots of Table objects connected to it. If I save on, it looks like this:
Restaurant *restaurant = [[Restaurant alloc] init];
restaurant.url = [_userData url];
restaurant.type = [_userData kind];
for (int i = 0; i < [[_userData tables] count]; i++) {
Input *input = [[_userData tables] objectAtIndex:i];
Table *table = [[Table alloc] init];
table.title = input.title;
table.seats = input.seats;
table.type = input.type;
[restaurant.tables addObject:table];
}
RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
config.fileURL = [NSURL URLWithString:[Preferences getRealmPath]];
RLMRealm *realm = [RLMRealm realmWithConfiguration:config error:nil];
[realm beginWriteTransaction];
[realm addObject:restaurant];
[realm commitWriteTransaction];
Now, what I want is that when a restaurant is added, but it already exists in that configuration, it's not stored. But when the same restaurant is added, but something is different - even if it's the amount of seats at 1 table - it should be added. What's the best way to achieve this?