Closed whyceewhite closed 9 years ago
This is occurring again, however, now I am certain why it is happening.
It turns out that just setting the managed object to nil
does not make the managed object go away. In certain situations (Log Tracked Trip, for example), a Trip managed object is created to hold the trip's in progress values. When the trip is completed the user can save or discard the trip. The problem occurs when the user discards the trip. The managed object for that trip exists. Therefore, the next time the managed object context is saved then that trip will be saved. The fact that the variable pointing to it is nil'ed out doesn't have anything to do with the managed object.
As a result, if the user discards the trip, the code needs to send a deleteObject message to the trip and then save the context. That seems weird since the trip object was never saved to begin with. However, that is the way to flush it from being in a pending state.
To recreate:
Happening... again.
Press the save button on the manual entry without having a distance value (or a value of zero). This will cause the validation to fail but the Trip
managed object will be created. Thus, when a save does occur, anywhere in the app, the random Trip
will be saved.
This is happening because the trip managed object instance is created prior to validation. Thus, if validation fails, then the trip object exists, will be in the managed context as pending and will be saved whenever the context is saved.
Random, unsaved trips are showing up in the Trip list scene again a la #8.
This happened before because the context manager was pulling back pending trips. That was turned off but now they are appearing again. Some code was introduced where Settings or Vehicles (?) should bring back pending changes. Perhaps the pending is global and not for just one entity.
Or, is this happening because a Setting or Vehicle update automatically creates a new Trip because there is a relationship?? If so, make the relationship optional in the class (if it isn't already).