NSManagedObject One-To-Many and pending changes

Hi - I have a question I hope I can get some help with in my Swift app.

I have a one-to-many relationship setup and have NSManagedObject subclasses going. So far so good.

It seems the Generated accessors that are created for the many side of the relationships automatically commit the additions to Core Data. I.e. if I fire the AddToXXX accessor both the one side and the many side get written…

Problem is that I have a situation whereby I don’t want that in my workflow. I want to build the one side and several related entities on the many side and write them all to CoreData at the same time - there may be an situation where I want to back the whole thing out and have nothing go to Core Data.

Can anyone suggest some ideas to make this happen?

I’m probably missing something here but I can’t see it.

Hope I’ve explained reasonably well - feel free to tell me I haven’t :slight_smile:

@pdelaney Thanks very much for your question, and my apologies for the delayed response.

First off, the only way to really commit changes to Core Data is by calling the save() function on your Managed Object Context.

Have you considered not using the generated accessor method, and simply doing things manually? Just because the function is available to you, doesn’t mean you have to use it. That would be my suggestion. For specialized, custom behaviour, feel free to use your own solution, and see if it works for you.

I hope this helps!

All the best!