我在核心数据中的两个实体之间有一个简单的有很多关系:
团队 <-------->> 游戏
当我将新的游戏托管对象插入上下文时,我需要在模型层查询团队实体的一些属性。但是,我使用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];
在 Rails 中我会使用@team.games.build,但这在 Core Data 中似乎是不可能的。