Skip to content

Commit

Permalink
fixing the tag relation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed Apr 8, 2024
1 parent 4c141ca commit 13ef198
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions inits/Models.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Models() {
mustRun(DB.AutoMigrate(&models.Setting{}))
mustRun(DB.AutoMigrate(&models.SystemResource{}))
mustRun(DB.AutoMigrate(&models.Tag{}))
mustRun(DB.AutoMigrate(&models.TagLinks{}))
}

func mustRun(err error) {
Expand Down
2 changes: 1 addition & 1 deletion models/Link.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Link struct {
UserID uint `json:"-"`
ParentFolder *Folder `json:"-"`
ParentFolderID uint
Tags []Tag `gorm:"many2many:links_tags;"`
Tags []*Tag `gorm:"many2many:tag_links;"`
}

type LinkListValidation struct {
Expand Down
21 changes: 17 additions & 4 deletions models/Tag.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package models

import (
"time"

"gorm.io/gorm"
)

type Tag struct {
Model
Name string `gorm:"size:128;"`
Links []Link `gorm:"many2many:links_tags;"`
UserId uint `gorm:"index"`
User User
Name string `gorm:"size:128;"`
UserId uint `gorm:"index" json:"-"`
User User `json:"-"`
Links []*Link `gorm:"many2many:tag_links;" json:"-"`
}

type TagLinks struct {
LinkID uint `gorm:"primaryKey"`
TagID uint `gorm:"primaryKey"`
CreatedAt time.Time
DeletedAt gorm.DeletedAt
}

type TagCreateValidation struct {
Expand Down

0 comments on commit 13ef198

Please sign in to comment.