0

I have a working model in coredata with two entity: - Customer - Invoices

Customer has "invoices" property (1 to many) and Invoices has "customer" property (1 to 1). Everything worked until i override the "setCustomer" method on Invoice class. I write this code

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

where "recalculatePriceAndDiscount" is my own method that i need to call when i select different customer.

When i use this code the inverse relationship (customer->invoices) isn't immediately available, i need to close and reopen my application to see customer's invoices.

There is some other method that i need to call?

thanks

IgnazioC
  • 4,554
  • 4
  • 33
  • 46
  • Possible duplicate of [Custom setter methods in Core-Data](https://stackoverflow.com/questions/2971806/custom-setter-methods-in-core-data) – malhal Mar 16 '18 at 23:24

1 Answers1

0

If the property is called "customer" (with a lower-case "c") then you have to use that as key, e.g.

[self willChangeValueForKey:@"customer"];
// ... etc. 
Tim Bodeit
  • 9,673
  • 3
  • 27
  • 57
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382