-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmany_2_many.go
34 lines (29 loc) · 1005 Bytes
/
many_2_many.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package publish
import "github.com/jinzhu/gorm"
type publishJoinTableHandler struct {
gorm.JoinTableHandler
}
func (handler publishJoinTableHandler) Table(db *gorm.DB) string {
if IsDraftMode(db) {
return handler.TableName + "_draft"
}
return handler.TableName
}
func (handler publishJoinTableHandler) Add(h gorm.JoinTableHandlerInterface, db *gorm.DB, source1 interface{}, source2 interface{}) error {
// production mode
if !IsDraftMode(db) {
if err := handler.JoinTableHandler.Add(h, db.Set(publishDraftMode, true), source1, source2); err != nil {
return err
}
}
return handler.JoinTableHandler.Add(h, db, source1, source2)
}
func (handler publishJoinTableHandler) Delete(h gorm.JoinTableHandlerInterface, db *gorm.DB, sources ...interface{}) error {
// production mode
if !IsDraftMode(db) {
if err := handler.JoinTableHandler.Delete(h, db.Set(publishDraftMode, true), sources...); err != nil {
return err
}
}
return handler.JoinTableHandler.Delete(h, db, sources...)
}