0
votes

I have an entity authors and another entity books where there is a one-to-many relationship of authors to books. Accordingly, I represent the books as an NSSet in a relationship to authors. If I want to delete or add books for an author, is Core Data smart enough for me just to alter the nsset of books for the author? Or do I need to specifically delete or add the book in the books entity?

In other words, is the following sufficient to change books for an author?

NSSet *bookSet = _author.books;
NSMutableSet *mutableBookSet = [NSMutableSet setWithSet:bookSet];
[mutableBookSet removeObject:bookToRemove];
newBookSet = mutableBookSet; 
_author.books = newBookSet;

or do I need to remove the book from the books entity?

Thanks for any suggestions.

1

1 Answers

0
votes

the above is enough to change the books of an author. yes.

dont forget to save the context but then all seems good