You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VERY excited for this feature. Thank you for the examples!
One area I'm confused about is adding a side-effect to a model CUD action.
This could be replacing the delete action with a custom delete action or making sure some log is always written on table creation. Is this possible?
Also in the docs it says extensions could be used for soft-deletes and for removing deletes entirely would love examples of these two usecases as well.
Also, does this work so that if you override a method on a model you can ensure that nested creates on other models will work as well? For example, if I want to make sure there is no delete method on a model and remove that operation how can I prevent a nested delete on all the other models?
The text was updated successfully, but these errors were encountered:
MichaelrMentele
changed the title
Examples for Before/After Hooks on Create
Examples for Before/After Hooks on Create/Update/Delete, Soft Deletes, and Removing Methods
Feb 23, 2023
// testdescribe('vehicle',()=>{it('delete method is undefined',async()=>{// The direct method is removed...expect(db.vehicle.delete).toBeUndefined()})it('nested deletes are undefined',async()=>{// the indirect delete is NOT prevented...constvehicle=awaitfakeVehicle()constvehicleCount=awaitdb.vehicle.count({where: {id: vehicle.id}})expect(vehicleCount).toBe(1)awaitdb.stage.update({where: {id: vehicle.stageId,},data: {vehicles: {delete: {id: vehicle.id,},},},})constnewVehicleCount=awaitdb.vehicle.count({where: {id: vehicle.id},})// without the extension, this SHOULD be 0// with the extension this SHOULD be 1 but either way// in both cases the new vehicle count is 0 meaning// the vehicle was deletedexpect(newVehicleCount).toBe(1)})})
VERY excited for this feature. Thank you for the examples!
One area I'm confused about is adding a side-effect to a model CUD action.
This could be replacing the delete action with a custom delete action or making sure some log is always written on table creation. Is this possible?
Also in the docs it says extensions could be used for soft-deletes and for removing deletes entirely would love examples of these two usecases as well.
Also, does this work so that if you override a method on a model you can ensure that nested creates on other models will work as well? For example, if I want to make sure there is no delete method on a model and remove that operation how can I prevent a nested delete on all the other models?
// extend model to disallow deletes
db.someModel.delete
<- should be undefinedThe text was updated successfully, but these errors were encountered: