Is there anyone can help me. I tried Delete-with-Select but it doesn't worked for me.
My gorm version as below:
gorm.io/driver/mysql v1.4.7
gorm.io/gorm v1.25.2
My model definition as below:
type Model struct {
ID uint `json:"id" gorm:"primarykey"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index" `
CreatorID string `json:"creatorID"`
UpdaterID string `json:"updaterID"`
}
type Attribute struct {
Model
Name string `json:"name"`
Desc string `json:"desc"`
Values []AttributeValue `json:"values"`
}
type AttributeValue struct {
Model
AttributeID uint `json:"attributeID"`
Value string `json:"value"`
}
Then I using the Delete-with-Select to softly delete the Attribute by ID, and the Attribute was softly deleted successfully, but the associated AttributeValue didn't be deleted.
func DelAttribute(id uint) error {
return Db.Select("Values").Delete(&Attribute{}, id).Error
}
Am I using it in a wrong way?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: jinzhu
Checkout the Note part in the above document link.
Associations will only be deleted if the deleting records’s primary key is not zero, GORM will use those primary keys as conditions to delete selected associations