Reputation: 1590
I have a customer object with two relationships, a document and an asset.
When I create an Asset I have a condition where I check for the existence of a document object in the customer. If it does not exist, I create one and set the document's customer relationship.
Right after that, I create the asset. However, I am getting a crash when trying to set the customer to the asset with an EXC_BAD_ACCESS.
Whats strange is this code use to work, but I have no idea what would of changed to suddenly cause a crash here.
this is the code:
if (![customer inspectionDocument]) //check if a document exists
{
// if it doesn't create one
Document *document = [Document newDocument];
document.customer = customer;
//sets additional properties
}
// now create the asset
Asset *asset = [Asset newObject];
asset.customer = customer; // <---- crash occurs here
//sets additional properties
Upvotes: 0
Views: 281
Reputation: 6844
I assume that you're using a relationship to store the customer reference to your document and asset. Normally, you should have a reverse relationship. Have you tried setting the document property on the customer object instead of the opposite?
if (![customer inspectionDocument]) {
// if it doesn't create one
customer.document = [Document newDocument];
}
customer.asset = [Asset newObject];
Upvotes: 1