@belgoros wrote:
I’m trying to understand the following use case. When we use one of
DS.Store
fetch methods likefindAll
,findRecord
, etc., all of them return aPromise
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 getProxy {_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 thestore
? Usestore.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.
Posts: 1
Participants: 1