NSPredicate retrieve a certain object
I have a Building entity and a Floor entity. There is a one-to-many relationship between them. Building<---->>Floor
Building has an attribute called buildingName. I want to retrieve an NSArray with floor entities according to a certain buildingName.
I have tried different kind of predicates, but I cant get it right.
If you have a Building class with a floor NSSet in it you can simply use:
Building *building = //get the building you need NSArray *building_floors = [building.floor allObjects];
If not, since floor has only 1 building, you can fetch the Floor entity with a predicate of the building name
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"building.buildingName == %@",building.buildingName];
(I assume that "building" is the name of the relationship in the Floor entity)