Closed robertoneto-senior closed 1 week ago
I'm also having this problem, and I'm also trying to report a bug related to many2many.
Any update on how to deal with the examples/dal
issue?
I also have this issue
So the issue here as I understand it is that /gen/examples
was made a submodule in this commit and as a result the current import strategy doesn't work. I don't know the go mod system well enough to recommend a fix but I've worked around this by cloning gen and using a replace directive to import the examples submodule from my local copy.
So the issue here as I understand it is that
/gen/examples
was made a submodule in this commit and as a result the current import strategy doesn't work. I don't know the go mod system well enough to recommend a fix but I've worked around this by cloning gen and using a replace directive to import the examples submodule from my local copy.
Could you please share what is the replace directive? I want to report an issue too.
Am just writing up a PR now but I've checked out the gen repo and am using:
replace gorm.io/gen/examples => ../gen/examples
which resolves the /examples
submodule correctly. For some reason I can't get this to work by requiring gorm.io/gen/examples v0.3.26
without replacing it with a local version, but I am pretty new to Go and perhaps I'm missing the special sauce for requiring a submod?
I commented out the following in gorm-playground/gen.go
:
package main
import (
"gorm.io/gen"
// "./gen/examples/dal" <<<<<<<<<<<<<<<<<<<<<<<<<<
)
func generate() {
g := gen.NewGenerator(gen.Config{
OutPath: "./dal/query",
Mode: gen.WithDefaultQuery, /*WithQueryInterface, WithoutContext*/
WithUnitTest: true,
})
// g.UseDB(dal.DB) <<<<<<<<<<<<<<<<<<<<<<<<<<
g.ApplyBasic(Company{}, Language{}) // Associations
g.ApplyBasic(g.GenerateModel("user"), g.GenerateModelAs("account", "AccountInfo"))
g.Execute()
}
then run ./test.sh
it fails much later:
2024/10/22 23:31:23 /tmp/gorm-playground/db.go:69
[error] failed to initialize database, got error read tcp 127.0.0.1:46478->127.0.0.1:9930: read: connection reset by peer
2024/10/22 23:31:23 failed to connect database, got error read tcp 127.0.0.1:46478->127.0.0.1:9930: read: connection reset by peer
FAIL gorm.io/playground 0.019s
FAIL
but this passes:
GORM_DIALECT=mysql go test
2024/10/22 23:32:06 testing mysql...
2024/10/22 23:32:07 /tmp/gorm-playground/main_test.go:14
[9.772ms] [rows:1] INSERT INTO `users` (`created_at`,`updated_at`,`deleted_at`,`name`,`age`,`birthday`,`company_id`,`manager_id`,`active`) VALUES ('2024-10-22 23:32:07.486','2024-10-22 23:32:07.486',NULL,'jinzhu',0,NULL,NULL,NULL,false)
2024/10/22 23:32:07 /tmp/gorm-playground/main_test.go:17
[0.524ms] [rows:1] SELECT * FROM `users` WHERE `users`.`id` = 1 AND `users`.`deleted_at` IS NULL ORDER BY `users`.`id` LIMIT 1
PASS
ok gorm.io/playground 1.139s
i've solved this problem with these steps:
clone github.com/go-gorm/gen
git clone git@github.com:go-gorm/gen.git
find all the "gorm.io/gen/examples" in "import", and replace them with "examples"
before:
import (
"xxxxxx"
"gorm.io/gen/examples"
"gorm.io/gen/examples/xxxx"
)
after:
import (
"xxxxxx"
"examples"
"examples/xxxx"
)
run go mod download in github.com/go-gorm/gen/examples
cd PATH/TO/YOUR/{github.com/go-gorm/gen/examples}
go mod download
update the go.mod in playground
# add this line
require gorm.io/gen/examples v0.3.25
replace gorm.io/gen/examples v0.3.25 => PATH/TO/YOUR/{github.com/go-gorm/gen/examples}
5. run test.sh in playgound
GORM Playground Link
Tried also to run
go clean -modcache
andgo clean -cache
, but the problem continues.Description
Just trying to fork this repository to report a bug related to many2many.