Skip to content

Commit

Permalink
feat: save method to model class
Browse files Browse the repository at this point in the history
  • Loading branch information
kkyouhei committed Nov 1, 2018
1 parent f7cc518 commit 6c8e68d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/model/Model.ts
Expand Up @@ -657,6 +657,19 @@ export default class Model {
}, {})
}

$save (): Model {
const fields = this.$fields()
const record = Object.keys(fields).reduce((record, key) => {
record[key] = this[key]
return record
}, {} as Record)

this.$dispatch('insertOrUpdate', { data: record }).catch((err) => {
throw err
})
return this
}

/**
* Serialize an item into json.
*/
Expand Down

0 comments on commit 6c8e68d

Please sign in to comment.