首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心数据中的多个关系

核心数据中的多个关系
EN

Stack Overflow用户
提问于 2011-05-13 10:41:26
回答 1查看 221关注 0票数 0

这是我的核心数据GeneratedCode,由xCode编辑器自动生成。

代码语言:javascript
复制
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Building, Category, City, District, Image, LatitudeLongitude, OpeningHour, Promotion, Rating, Review, URL;

@interface Business : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * Website;
@property (nonatomic, retain) NSString * Email;
@property (nonatomic, retain) NSString * Street;
@property (nonatomic, retain) NSString * InBuildingAddress;
@property (nonatomic, retain) NSString * Phone;
@property (nonatomic, retain) NSString * Title;
@property (nonatomic, retain) NSString * Zip;
@property (nonatomic, retain) NSNumber * Price;
@property (nonatomic, retain) NSSet* Promotions;
@property (nonatomic, retain) Building * Building;
@property (nonatomic, retain) NSSet* Categories;
@property (nonatomic, retain) LatitudeLongitude * LatitudeLongitude;
@property (nonatomic, retain) NSSet* Images;
@property (nonatomic, retain) OpeningHour * OpeningHour;
@property (nonatomic, retain) NSSet* Reviews;
@property (nonatomic, retain) NSSet* URLs;
@property (nonatomic, retain) Rating * Rating;
@property (nonatomic, retain) NSSet* Districts;
@property (nonatomic, retain) City * City;

//我添加了这3行,为什么不是自动生成代码的一部分?

代码语言:javascript
复制
- (void)addDistrictsObject:(District *)value;
- (void)addCategoriesObject:(Category *)value;
- (void)addReviewsObject:(Review *)value;

@end

假设我想“清除”所有评论和图片。

做self.Reviews=nil能解决这个问题吗?

我知道做self.LatitudeLongitude=nil会删除self和它的LatitutudeLongitude之间的关系。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-13 11:52:32

编辑-不确定你的意思是不是像delete中那样是“清除”。下面我的回答是假设您希望对象从上下文中移除;而不仅仅是切断NSManagedObjects

我不相信

代码语言:javascript
复制
self.Reviews = nil;

将实际删除托管对象上下文的审阅对象。这将向每个对象发送释放消息,但是要从您必须调用的上下文中删除它们

` `aContext :reviewObj;`

在集合中的每一个上。如果您要删除一个业务对象(使用如上所示的"deleteObject“),并且您将关系删除规则设置为"Cascade",那么我相信这将导致所有的评论、城市等……自动删除该业务对象所拥有的对象,但据我所知,这是导致NSManagedObjects被删除的唯一其他方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5986728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档