pinia-orm icon indicating copy to clipboard operation
pinia-orm copied to clipboard

fresh() doesn't call any lifecycle Hook

Open abd777 opened this issue 2 years ago • 3 comments

Environment

No response

Reproduction

Playground

Describe the bug

I need to listen for the lifecycle hook inside the Model when the fresh() is called , but no any lifecycle hook is listening to fresh() while if i use save() it works

For now i'm using this as a workaround

const repo = useRepo(REPO_NAME)
// clear everything
repo.flush()
// then save , i.e to trigger the lifecycle
repo.save(NEW_DATA)

ideally fresh() should also be a lifecycle hook trigger

Additional context

No response

Logs

No response

abd777 avatar Nov 01 '23 11:11 abd777

Actually, it can be useful, if you have one mutator that doesn't trigger the hooks. For example, if you need to save raw data from a backend.

harmyderoman avatar Nov 23 '23 18:11 harmyderoman

@harmyderoman I agree with you , But the issue is that in most cases we need to check the hooks ( as we're using saving
and other hooks for other functions )

May be we can add an optional raw parameter like {raw:true} as the last config object and if raw is true we can keep it as it is , otherwise we can listen for the hooks

abd777 avatar Nov 25 '23 08:11 abd777

Hmmm interesting. I try to get my thoughts around that. You both have valid points. I think flush is getting hooks and i also add the option to avoid hooks.

CodeDredd avatar Jan 16 '24 22:01 CodeDredd