vue-api-query
vue-api-query copied to clipboard
Double updating child model causes error
Hey guys I've just crashed face first into a problem when trying to update a child model more than once.
It looks like on the second attempt of me updating a model this seems to be happening TypeError: Cannot redefine property: _fromResource
, has anyone ran into this before and if so how did u solve it?
Best regards, Luis Bizarro.
You might have trouble re-using the model, yes. Currently I overwrite the model instance with the response of the update, see below.
The backend might do something to the model when saving, so it is a good idea to keep backend and frontend in sync anyway.
new Task(this.task)
.save()
.then(task => {
this.task = task;
})
.catch(error => {
// ...
});
I have never gotten the "Cannot redefine property" error with this. This of course assumes the backend returns the saved model.
@WildEgo Has the comment helped you fix your problem? Can we close this issue?
Today ran into a similar problem. Only the first call of patch() (and save() as well) is successful, any further attempt to call save() or patch() fails with exception.
async created() {
this.user = await User.find(2)
},
// console
$vm0.user.settingsIsDark = false // false
$vm0.user.patch() // Promise {<pending>}
$vm0.user.settingsIsDark = true // true
$vm0.user.patch()
Model.js?b77e:89 Uncaught TypeError: Cannot redefine property: _config
at Function.defineProperty (<anonymous>)
at User.config (Model.js?b77e:89)
at User.patch (Model.js?b77e:594)
at <anonymous>:1:11
Today ran into a similar problem. Only the first call of patch() (and save() as well) is successful, any further attempt to call save() or patch() fails with exception.
async created() { this.user = await User.find(2) },
// console $vm0.user.settingsIsDark = false // false $vm0.user.patch() // Promise {<pending>} $vm0.user.settingsIsDark = true // true $vm0.user.patch() Model.js?b77e:89 Uncaught TypeError: Cannot redefine property: _config at Function.defineProperty (<anonymous>) at User.config (Model.js?b77e:89) at User.patch (Model.js?b77e:594) at <anonymous>:1:11
Got this problem too