Is it possible for a managed object to have a relationship with ‘optional’ unchecked?
If so, how can I insert it without having validateForInsert: fail?
I want the relationship to be mandatory but I am unable to establish a connection between the current and another object before inserting it because the two objects I want to connect are in different contexts.
Concrete Example:
I generally have one MOC. Let’s say I have a Person saved in the context.
Now I want to create a new one, so I instantiate a Person but do not insert it into the context yet. When the user picks a brother from some table view and I set the ‘brother’ property, the inverse relationship would attempt to establish a connection between the object saved in the MOC and the one that does not exist in the MOC yet, which would cause the app to crash.
My Question: if the ‘brother’ relationship would not be optional, could I even create and insert a new person?
What a dumb question of myself.
Of course you can insert an object into the context without causing an error. You can then set up the (mandatory) relationships.
The validation of relationships and properties only occurs when actually trying to save the context.
In my app however, I did not insert the entity until the ‘NewItemVC’ finished. I called -validateForInsert: on the object being created to check if it’s valid an enable/disable the done button.
Since I cannot establish the mandatory relationship without inserting it, this is not a good idea, I gotta think of something new.