0

我在 coredata 中有一个具有两个实体的工作模型: - 客户 - 发票

客户具有“发票”属性(1 对多),发票具有“客户”属性(1 对 1)。一切正常,直到我覆盖 Invoice 类的“setCustomer”方法。我写这段代码

-(void)setCustomer:(Customer *)customer {
    [self willChangeValueForKey:@"Customer"];
    [self setPrimitiveValue:customer forKey:@"Customer"];
    [self didChangeValueForKey:@"Customer"];
    [self recalulatePriceAndDiscounts];
}

其中“recalculatePriceAndDiscount”是我自己选择不同客户时需要调用的方法。

当我使用此代码时,反向关系(客户->发票)不是立即可用的,我需要关闭并重新打开我的应用程序以查看客户的发票。

我需要调用其他一些方法吗?

谢谢

4

1 回答 1

0

如果该属性称为“客户”(带有小写“c”),那么您必须使用它作为键,例如

[self willChangeValueForKey:@"customer"];
// ... etc. 
于 2012-11-04T16:10:02.890 回答