gen icon indicating copy to clipboard operation
gen copied to clipboard

模型在多个目录下无法正确处理包引用

Open goodking-bq opened this issue 2 years ago • 5 comments

GORM Playground Link

https://github.com/go-gorm/playground/pull/1

Description

/mnt/c/Users/goodk/GolandProjects/gen-test 15s ❯ tree 21:44:40

.
├── a
│   └── model
│       └── models.go
├── b
│   └── model
│       └── models.go
├── go.mod
├── go.sum
├── main.go
└── query
    ├── as.gen.go
    ├── bs.gen.go
    └── gen.go
// a/model/models.go
package model

type A struct {
	ID   uint
	Name string
}
// b/model/models.go
package model

import (
	"gen-test/a/model"
)

type B struct {
	AID uint
	A   *model.A
	Six string
}

b模型的gen文件因为使用b/model, 而b/model 没有 struct A 而报错

goodking-bq avatar May 20 '23 13:05 goodking-bq

@goodking-bq try conf.WithImportPkgPath("gen-test/a/model")

qqxhb avatar Jun 07 '23 09:06 qqxhb

@qqxhb thanks,but not work for me .

goodking-bq avatar Jun 19 '23 10:06 goodking-bq

I have the same issue. May I ask if this issue has been resolved?

MisakaTAT avatar Oct 18 '23 05:10 MisakaTAT

1, must use master branch

go get -u gorm.io/gen@master

2, use WithImportPkgPath

	c := gen.Config{ ... }
	c.WithImportPkgPath(
		`a "gen-test/a/model"`,
		`b "gen-test/b/model"`,
	)

radioinmyhead avatar Feb 01 '24 06:02 radioinmyhead

1, must use master branch

go get -u gorm.io/gen@master

2, use WithImportPkgPath

	c := gen.Config{ ... }
	c.WithImportPkgPath(
		`a "gen-test/a/model"`,
		`b "gen-test/b/model"`,
	)

i tried, but not work ,why? repo

goodking-bq avatar Apr 15 '24 03:04 goodking-bq