Gorm: Create of soft-deleted object should un-delete

Created on 10 Oct 2015  路  6Comments  路  Source: go-gorm/gorm

I get a primary key violation when I db.Create an item that has been soft deleted. Alternatively, when I update the soft-deleted item with a DeletedAt value that indicates that it shouldn't be deleted, maybe that should undelete it. As it stands, neither of these works.

Most helpful comment

I understand you addressed the Update case here but creation is still an issue. If you Create a soft-deleted record it will fail with a primary key violation error.

All 6 comments

https://github.com/jinzhu/gorm#soft-delete

Are you using Unscoped

I understand you addressed the Update case here but creation is still an issue. If you Create a soft-deleted record it will fail with a primary key violation error.

Is here a way to solve the problem?

@jinzhu

http://gorm.io/docs/delete.html#Delete-record-permanently

@jinzhu
Thanks for Jinzhu's reply. Does it have another way to INSERT previous-soft-deleted data in replace with INSERT the data before delete record permanently?

My purpose is to keep all columns of the particular deleted data, and when do next INSERT action, just replace some columns need to be updated but primary key, of course let deleted_at to be NULL.

If I do the hard-delete action before CREATE action, I can't get the column info. before I delete the data. (p.s Of course I can use some tricky way like query the data before hard delete to resume the column info. lol)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

easonlin404 picture easonlin404  路  3Comments

bramp picture bramp  路  3Comments

littletwolee picture littletwolee  路  3Comments

koalacxr picture koalacxr  路  3Comments

Quentin-M picture Quentin-M  路  3Comments