user1923809
user1923809

Reputation: 159

NSManagedObject deleted but relationship doesnt get updated

I have data structure like this

A--->>B (A has one to many relationship with B and relationship name is images)

I fetch the "A" objects and then use "B" objects in my app. At one operation I am deleting B objects from . EVerything is fine and B objects get deleted and I can Immedately see the effects in my app as data conained in them doesnt gets displayed. But what happens is that A object still returns the previous count of B Objects which I confirmed with NSLog(@"%d",[a.relation count]).

ie if there were 6 B objects initially then after deleting 2 objects still it shows 6 objects which should be 4.

Upvotes: 1

Views: 252

Answers (1)

Martin R
Martin R

Reputation: 539765

You have to define an inverse relationship from "B" to "A" and set the "Delete Rule" of this relationship to "Nullify".

However, the "A" object is only updated when you save the managed object context, or if you call processPendingChanges for the context.

Upvotes: 1

Related Questions