feat: foreignKeys check
+fix: "unnamed" field bug
This commit is contained in:
12
tests/foreign_key_check_test.go
Normal file
12
tests/foreign_key_check_test.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/analysis/analysistest"
|
||||
"gormlint/foreignKeyCheck"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestForeignKeyCheck(t *testing.T) {
|
||||
t.Parallel()
|
||||
analysistest.Run(t, analysistest.TestData(), foreignKeyCheck.ForeignKeyCheck, "foreign_key_check")
|
||||
}
|
||||
12
tests/testdata/src/foreign_key_check/negative.go
vendored
Normal file
12
tests/testdata/src/foreign_key_check/negative.go
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
package foreign_key_check
|
||||
|
||||
type User struct {
|
||||
Name string
|
||||
CompanyRefer uint
|
||||
Company Company `gorm:"foreignKey:CompanyRefer"`
|
||||
}
|
||||
|
||||
type Company struct {
|
||||
ID int
|
||||
Name string
|
||||
}
|
||||
27
tests/testdata/src/foreign_key_check/positive.go
vendored
Normal file
27
tests/testdata/src/foreign_key_check/positive.go
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
package foreign_key_check
|
||||
|
||||
type PrepTask struct {
|
||||
Id uint `gorm:"primaryKey"`
|
||||
Description string
|
||||
TaskId uint
|
||||
WorkAreaId uint
|
||||
WorkArea `gorm:"foreignKey:WorkAreaIds;constraint:OnDelete:CASCADE;"` // want "Foreign key \"WorkAreaIds\" mentioned in tag at field \"WorkArea\" doesn't exist in model \"PrepTask\""
|
||||
Deadline int64
|
||||
}
|
||||
|
||||
type WorkArea struct {
|
||||
Id uint `gorm:"primaryKey"`
|
||||
Name string
|
||||
Description string
|
||||
Performance uint
|
||||
PrepTasks []PrepTask `gorm:"constraint:OnDelete:CASCADE;"`
|
||||
}
|
||||
|
||||
type Shift struct {
|
||||
Id uint `gorm:"primaryKey"`
|
||||
Description string
|
||||
ProductAmount uint
|
||||
ShiftDate int64
|
||||
WorkAreaId string // want "Foreign key should have type like int, not \"string\""
|
||||
WorkArea WorkArea `gorm:"foreignKey:WorkAreaId;"`
|
||||
}
|
||||
Reference in New Issue
Block a user