Skip to content

Commit

Permalink
fix(pinia-orm): $refresh() is not working (#1125)
Browse files Browse the repository at this point in the history
closes #1124
  • Loading branch information
CodeDredd authored Mar 27, 2023
1 parent 84aeb72 commit 7cf0d6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/pinia-orm/src/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,11 @@ export class Model {
* Return the model instance with its original state
*/
$refresh(): this {
this.$isDirty() && this.$fill(this.$getOriginal(), { action: 'save', relations: false, operation: 'set' })
if (this.$isDirty()) {
Object.entries(this.$getOriginal()).forEach((entry) => {
this[entry[0]] = entry[1]
})
}
return this
}

Expand Down
1 change: 1 addition & 0 deletions packages/pinia-orm/tests/unit/model/Model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('unit/model/Model', () => {
expect(user.$isDirty('id')).toBeFalsy()
user.$refresh()
expect(user.$isDirty()).toBeFalsy()
expect(user.lastName).toBe('John Doe')
expect(() => user.$isDirty('name')).toThrowError()
})
})

0 comments on commit 7cf0d6e

Please sign in to comment.