EmbeddedRecordsMixin saving belongsTo

I know there’s some pending issues related to saving embedded relationships but I’m not 100% sure this case falls under the un-implemented changes.

I have a parent model with a belongsTo relationship and there’s two different scenarios I need to handle:

  1. Creating a new record and saving
  2. Updating an existing record and saving

For case 1, I am saving the parent and removing any child records lingering in the store with id == null which works fine.

For case 2, I am saving the parent but the child record is remaining in the dirty state. Is there any similar workarounds for existing records that I can use such as in case 1 where my store is in a clean state after saving? Or is this a case that should be working but somehow being mishandled on my end?

From my understanding, the issues with case 1 is that the client-side record has no id and therefore no explicit way of correlating the embedded record in the save response to the one on the client. For case 2, both client and server already have correlated IDs for the embedded record so I would expect the save response to just overwrite the dirty attributes in the store.

After further investigation, it seems like the store is properly normalizing the update response but if the local changes slightly differ from the update response then the local changes are prioritized on the child record and it is still considered in the “dirty” state. Calling a rollbackAttributes() after the parent has successfully saved on the child works but still seems odd to me.

let embeddedRecord = parentRecord.embedded;

return parentRecord.save().then((saved) => {
    // Workaround for new embedded records with 'null' id
    if(embeddedRecord.isNew) {
        embeddedRecord.deleteRecord();
    }
    // Workaround for existing records to stay in sync with response from PUT request
    else {
        embeddedRecord.rollbackAttributes();
    }
})

And just for further cleanup, seems like rollbackAttributes() is a suitable workaround for both scenarios.

let embeddedRecord = parentRecord.embedded;

return parentRecord.save().then((saved) => {
        embeddedRecord.rollbackAttributes();
})