I have a core data model with 2 entities: Collection and Image. There's a one to many relationship between Colletion and Image, reflected by an 'images' accessor on the Collection side and a 'collection' accessor on the Image side.
There's an additional relationship called keyImage, which is a 1:1 relationship between Collection and Image. One of the images in the collection is the key image and I've modeled that by creating an additional 1:1 relationship. This one has an accessor called keyImage in Collection and isKeyImageFor in Image.
I can work with this model mostly fine, there is however one thing that doesn't work.
// Add an image as the key image.
coll.keyImage = keyImage;
// Add the image to the collection
[coll addImagesObject:keyImage];
Both of these lines work independently. However, if I do both (the image should both be in the collection and assigned as the keyImage) then keyImage ends up being null after saving the data. It's as if the 1:N relationship nullifies the 1:1 relationship, even though they use separate keys and accessors.
Any idea how I can get this to work?