My model has a Filter object and a Color object. I want two To-Many relationships between them: backgrounds and foregrounds. (that is, each “Filter” contains an array of background colors and an array of foreground colors, all of type “Color”).
I have two problems. Firstly, when I establish relationships, the inversion of “Color” can have only one value (I assume that this means that I cannot do what I want). Secondly, I cannot figure out how to create a predicate to extract only backgrounds or only foreground. I assume that they will all be combined together (if they work at all):
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Color"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"filter == %@", self];
I am going to solve this problem by converting Color to two Foreground and Background objects, but I do not want to do this without understanding why one object will not work. Did I miss something?
NOTE. This is apparently not intuitive for me. I ran into this exact problem again, but this time I did not use predicates, so I did not immediately find the problem. I had a very similar setting, but when I tried to remove the child, it will disappear first, but when I restarted the application, it will appear again. The more children I removed, the more I did. In the end, I noticed that the same children were in both arrays of relationships, and when I looked at the graphic version of the model, only one of these relationships had an arrow associated with the child. Finally, I remembered that I had this problem before! I do not understand very well what is happening, but it is clear that there are two child "arrays" where they merge together in a strange way.
source share