开发者

iphone core data:Unable to Delete data with one to many relationship

I am new on core data and found one issue. I have two classes A and B with relationship One to Many (multiple B object can refer to one A object).

A<--->>B

I want to execute Delete query of ManagedObjectContext with some certain criteria, but I am unable to delete. It might be issue of Delete Relationship Rule (Deny, No Action, Nullify and Cascade) and I tried certain combination of it. But I am unable to Delete them.

Here is the same code which I mean to execute:-

for (A *value in allDeleteObject)
{
  NSError *error;
  for (B *objB in [value.BDetails allObjects])
  {
    [managedObjectContext deleteObject:objB];
    [value removeGodetailsObject:objB];

    if (![managedObjectContext save:&error])
    {
    NSLog(@"%@",error);
    }
  } 
}

Please do tell me, if I am doing anything wr开发者_如何学JAVAong. Thanks in advance!!


for (A *value in allDeleteObject)
{
  NSError *error;
  NSArray *array = [value.BDetails allObjects];
  for (B *objB in array)
  {
    [managedObjectContext deleteObject:objB];
    [value removeGodetailsObject:objB];

    if (![managedObjectContext save:&error])
    {
    NSLog(@"%@",error);
    }
  } 
}

and use cascade delete rule at A and nullify at B.

Screen shot of Model:-

iphone core data:Unable to Delete data with one to many relationship

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜