Convert a Proxy object to Ember Data before calling save()


#1

I’m trying to understand the following use case. When we use one of DS.Store fetch methods like findAll, findRecord, etc., all of them return a Promise object. But if later you try to get the previously fetched Promise object and set a new value on one of its attributes, for example:

export default Controller.extend({
  currentUser: service(),
  currentShop: service(),
...
  actions: {
    async update() {
      let shop =  this.get('currentShop.shop');
      shop.set('modifiedBy', this.get('currentUser.user').get('username'));
      await shop.save();
 }

you will get an error like

shop.save() is not a function

When checkin what kind of shop is, you will get

Proxy {_belongsToState: BelongsToRelationship, isFulfilled: true, isRejected: false, _super: ƒ}

The question is what is the right way to get around of this, knowing that the above Shop instance has been already fetched and is available in the store? Use store.peekRecord() method like this:

let shop = store.peekRecord('shop', this.get('currentShop.shop.id'));
shop.set('modifiedBy', this.get('currentUser.user').get('username'));
await shop.save();

or there is another way ?

Thank you.