我在核心数据中有两个实体之间 有着许多关系:
团队 & lt; -- -- -- -- & gt; & gt; 游戏
当我在上下文中插入一个新的游戏管理对象时,我需要在模型层查询团队实体的某些属性。然而,当我使用 awakeFromInsert
时,关系尚未确定,所以 team
是 nil
。
// game.m
- awakeFromInsert
{
[super awakeFromInsert];
if ([self team] isActive] {
//.... set game properties
}
}
在要求插入和确定以下关系之前,是否有办法建立这种关系:
Game *newGame = [NSEntityDescription insertNewObjectForEntityForName:@"Game"
inManagedObjectContext:managedObjectContext];
[newGame setTeam:team];
在铁路上,我会使用