Does Primary Key Automatically Update If You Delete A Row
Delete
Delete a Tape
When deleting a tape, the deleted value needs to have primary key or it will trigger a Batch Delete, for example:
Delete with principal key
GORM allows to delete objects using chief key(south) with inline status, it works with numbers, check out Query Inline Weather condition for details
Delete Hooks
GORM allows hooks BeforeDelete
, AfterDelete
, those methods will exist chosen when deleting a tape, refer Hooks for details
Batch Delete
The specified value has no primary value, GORM will perform a batch delete, it will delete all matched records
Cake Global Delete
If yous perform a batch delete without any weather, GORM WON'T run it, and will return ErrMissingWhereClause
error
Yous accept to apply some weather or use raw SQL or enable AllowGlobalUpdate
fashion, for example:
Returning Data From Deleted Rows
Return deleted data, only works for database support Returning, for instance:
Soft Delete
If your model includes a gorm.DeletedAt
field (which is included in gorm.Model
), information technology volition get soft delete ability automatically!
When calling Delete
, the record WON'T exist removed from the database, merely GORM will set up the DeletedAt
'southward value to the current fourth dimension, and the data is not findable with normal Query methods anymore.
If y'all don't want to include gorm.Model
, you can enable the soft delete feature similar:
Find soft deleted records
Y'all can find soft deleted records with Unscoped
Delete permanently
You tin can delete matched records permanently with Unscoped
Delete Flag
Use unix second as delete flag
INFO when using unique field with soft delete, you should create a composite index with the unix second based
DeletedAt
field, e.thousand:
Use one
/ 0
as delete flag
Source: http://gorm.io/docs/delete.html
Posted by: smithaftervare.blogspot.com
0 Response to "Does Primary Key Automatically Update If You Delete A Row"
Post a Comment