In the context of a route model that hasn't been persisted to the backend yet (its id is null
still and we haven't called save
yet), if we want to discard the record, is it more correct to use unloadRecord
or destroy
?
Context: For use when a form is transitioned away from but is neither saved nor canceled. I'm new to ember and I am a bit confused by the fact that unloadRecord
is private for Model but not for Store. It may be obvious but I am also not positive when it is correct to refer to the object as a model vs. a record (I am assuming they are sometimes used interchangeably but it's technically correct to call them records if they are existing instances).
If you create but don't save a record it will be in the root.loaded.created.uncommitted
state (Ember 2.4). Calling destroyRecord
will schedule a save
but will also immediately change the state to root.deleted.saved
, so the save
request will never be executed.
You can verify this in your browser by checking the network requests created by calling destroyRecord
on an newly created record.
There is some additional work performed around scheduling a save
when calling destroyRecord
as opposed to unloadRecord
, so the trade-off here is between scheduling a save that is never executed and the additional complexity of determining the model state prior to deleting the record.
unloadRecord
- unloads record from the store
deleteRecord
- delete the record but do not save it (must call save
)
destroyRecord
- calls deleteRecord
and save
rollbackAttributes
- rolls back attributes or, if model isNew
, removes it from the store
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With