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
typeExercisestruct {
gorm.Model// Embedding gorm.ModelNamestring`json:"name"`Descriptionstring`json:"description"`MuscleGroupIDuint`json:"muscle_group_id"`// Foreign key for MuscleGroupMuscleGroupMuscleGroup`gorm:"foreignKey:MuscleGroupID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`// Association
}
Now I have an endpoint to delete a particular musclegroup, since my models follow a has-one relationship, When I delete a muscle group, I need the exercises using this muscle group as reference to be deleted. I've gone though the docs on soft delete and using select statement during delete. I added the clause.Associations now , but still the record for the exercise is present in the database. The referencing muscle group data shows empty when I query the exercise, but the muscle group is present. I was expecting the associated exercise to undergo a soft delete. Delete Query
// Delete the muscle group from the databaseiferr:=dbConn.Select(clause.Associations).Delete(&muscleGroup).Error; err!=nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "error deleting muscle group"})
return
}
Your Question
I have models as follows,
Now I have an endpoint to delete a particular musclegroup, since my models follow a has-one relationship, When I delete a muscle group, I need the exercises using this muscle group as reference to be deleted. I've gone though the docs on soft delete and using select statement during delete. I added the
clause.Associations
now , but still the record for the exercise is present in the database. The referencing muscle group data shows empty when I query the exercise, but the muscle group is present. I was expecting the associated exercise to undergo a soft delete. Delete Query##Related Issue I've gone through
#3702
The document you expected this should be explained
Expected answer
How can I delete the associated records in exercise table as a part of cascade delete , when I delete the muscle group.
The text was updated successfully, but these errors were encountered: