Skip to content

Commit 1ecce14

Browse files
committed
fix(providers): after delete hook on repos (closes bleenco#474)
1 parent 4cb1297 commit 1ecce14

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: server/core/provider.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package core
22

3-
import "time"
3+
import (
4+
"time"
5+
6+
"github.com/jinzhu/gorm"
7+
)
48

59
type (
610
// Provider represents `providers` db table.
@@ -42,3 +46,12 @@ type (
4246
Sync(uint) error
4347
}
4448
)
49+
50+
// AfterDelete hook on provider which deletes all related repositories.
51+
func (p *Provider) AfterDelete(tx *gorm.DB) error {
52+
return tx.Model(&Repository{}).
53+
Where("provider_id = ?", p.ID).
54+
Unscoped().
55+
Delete(&Repository{}).
56+
Error
57+
}

0 commit comments

Comments
 (0)