Models don't emit the "create" event on creation
tosty33 opened this issue · 5 comments
tosty33 commented
Models don't emit the "create" event on creation
sergiuwd commented
A quick fix I applied on Model.js
which will look into whether or not the saved version has an id:
onSaveSuccess(response) {
// Find if it's a create or update action
let action = 'create';
if (this.saved('id')) {
action = 'update'
}
// Clear errors because the request was successful.
this.clearErrors();
// Update this model with the data that was returned in the response.
if (response) {
this.update(response.getData());
}
Vue.set(this, 'saving', false);
Vue.set(this, 'fatal', false);
// Automatically add to all registered collections.
this.addToAllCollections();
this.emit('save', {error: null});
this.emit(action, {error: null});
}
Also, it should emit save.success
, not save
. I am implementing the code in one large-ish scale project and I will generate pull requests with proper fixes for more issues I'm running into.
rtheunissen commented
@sergiuwd could you please submit a PR for that? Looks good to me.
sergiuwd commented
@rtheunissen submitting a PR with more fixes.
sergiuwd commented
@Crypton33 here's a better fix:
https://github.com/sergiuwd/vue-mc/blob/patch-2/src/Structures/Model.js
rtheunissen commented
I believe this has now been fixed, as part of v0.6.0.