I’m trying to use customized join tables with GORM but everytime I need fetch data it says table does not exist even it existing. But when I use the method SetupJoinTable
it woks fine. So do I really need to call SetupJoinTable
every single time I create a gorm connection ?
This code does not work(Tables already created)
<code>db, err := GetGorm()
if err != nil {
panic(err)
}
var l Foo
db = db.Model(&l).Joins("Bars").Find(&l)
if db.Error != nil {
panic(db.Error)
}
println("size of bars is", len(l.Bars))
</code>
<code>db, err := GetGorm()
if err != nil {
panic(err)
}
var l Foo
db = db.Model(&l).Joins("Bars").Find(&l)
if db.Error != nil {
panic(db.Error)
}
println("size of bars is", len(l.Bars))
</code>
db, err := GetGorm()
if err != nil {
panic(err)
}
var l Foo
db = db.Model(&l).Joins("Bars").Find(&l)
if db.Error != nil {
panic(db.Error)
}
println("size of bars is", len(l.Bars))
but this code works fine:
<code> db, err := GetGorm()
if err != nil {
panic(err)
}
_ = db.SetupJoinTable(&Foo{}, "Bars", &FooBar{})
_ = db.SetupJoinTable(&Bar{}, "Foos", &FooBar{})
var l Foo
db = db.Model(&l).Joins("Bars").Find(&l)
if db.Error != nil {
panic(db.Error)
}
println("size of bars is", len(l.Bars))
</code>
<code> db, err := GetGorm()
if err != nil {
panic(err)
}
_ = db.SetupJoinTable(&Foo{}, "Bars", &FooBar{})
_ = db.SetupJoinTable(&Bar{}, "Foos", &FooBar{})
var l Foo
db = db.Model(&l).Joins("Bars").Find(&l)
if db.Error != nil {
panic(db.Error)
}
println("size of bars is", len(l.Bars))
</code>
db, err := GetGorm()
if err != nil {
panic(err)
}
_ = db.SetupJoinTable(&Foo{}, "Bars", &FooBar{})
_ = db.SetupJoinTable(&Bar{}, "Foos", &FooBar{})
var l Foo
db = db.Model(&l).Joins("Bars").Find(&l)
if db.Error != nil {
panic(db.Error)
}
println("size of bars is", len(l.Bars))
So do I need to call it everytime ?
(I’m so sorry ’bout my english, I’m not native)