zoukankan      html  css  js  c++  java
  • iOS coredata 级联删除

    应用场景如下,每个用户可以设定多个提醒,当删除一个用户时,应当把相关的提醒都删除,而删除一个提醒时,应当把提醒从用户信息中删除。

    那么 Profile 应该建立一个如下图的relationship

    而 reminder 应该建立如下图的relationship

    当向一个profile添加reminder时,要设定好2个对象的relationship,见如下例子代码:

            
            if(profile != nil){
                
                reminder.profileId = CURRENT_PROFILE.pId;
                reminder.contents = @[@"first contents"];
                reminder.type = [NSNumber numberWithInt:self.type];
                reminder.repeatType = [NSNumber numberWithInt:eRepeatTypeWeekly];
                reminder.profile = profile;
                
                NSMutableSet *reminderSet = [[NSMutableSet alloc] initWithSet:profile.reminder];
                [reminderSet addObject:reminder];
                profile.reminder = reminderSet;

          //也可使用系统自动创建的函数设置reminder!

               // [profile addReminderObject:reminder];

    
            
            
            }

    经过以上的过程,当你从数据库删掉一个profile时,与之相关的reminder都会被自动删除。

    这里需要注意的就是设置一个对象的relationship 的delete rule时,指的是删除本对象时,要对这个relationship属性怎么处理。

  • 相关阅读:
    如何让json_decode解码变的更加强壮
    scp命令
    Centos7安装postgresql
    ubuntu安装Java环境
    ubuntu开放端口
    VMware安装Ubuntu
    redis主从安装
    redis主从学习
    redis集群学习
    C++ 09 顺序容器
  • 原文地址:https://www.cnblogs.com/breezemist/p/4548666.html
Copyright © 2011-2022 走看看