如果我搜索Customer
对象并且发现客户存在,那么我想将该Customer
对象分配给新invoice.customer
对象的Invoice
属性。我可以这样做吗?
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Customer" inManagedObjectContext:self.objectContext]];
request.returnsObjectsAsFaults=NO; //populate beverage object
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(id == %@)", customerID];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *array = [self.objectContext executeFetchRequest:request error:&error];
if([array count] == 1)
{
invoice.customer = (Customer*)[array objectAtIndex:0];
}
我想避免的是必须将Customer
的所有属性值重新分配给invoice.customer
。这样做有什么考虑吗?