So let's assume I have something like this
type Foobar struct {
gorm.Model
Name string
}
....
var foo Foobar
db.SingularTable(true)
db.Model(&foo).Updates(Foobar{Name: "some_string"})
This will throw an error like:
(pq: relation "foobars" does not exist)
So my guess would be that currently db.SingularTable(true) is not being honored when calling db.Model().Updates()? Or maybe I just made a mistake here?
Have u got test code..
Can confirm I had this same problem today.
Code:
type Account struct {
LastOnline utils.NullTime
// other stuff elided
}
...
db, err := gorm.Open("sqlite3", dbFile)
db.SingularTable(true)
db.Model(Account{}).Where("last_online IS NULL").Updates(Account{ LastOnline: now })
Produces:
no such table: accounts
I have encounter same issue. Is there any resolution available?
Can't reproduce this on my local
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
type Account struct {
gorm.Model
Name string
}
func main() {
db, _ := gorm.Open("sqlite3", "/tmp/gorm.db")
db.LogMode(true)
db.SingularTable(true)
db.DropTable(&Account{})
db.AutoMigrate(&Account{})
db.Model(Account{}).Updates(Account{Name: "hello"})
}

You can't reproduce it so you close the issue? This was filed in April last year and still hasn't been fixed 9 months later.
You can't reproduce it so you close the issue?
So?
This was filed in April last year and still hasn't been fixed 9 months later.
Most issues not following our guide https://github.com/jinzhu/gorm/blob/master/CONTRIBUTING.md, and most of them are misreported because they just don't read the document...
Please respect our time, if you try to proven your issue with a runnable script or create a PR, you will be appreciated.
It fails to honor SingularTable when the first call is Model().Updates(). Issue can be reproduce using the following code,
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
type Account struct {
gorm.Model
Name string
}
func main() {
db, _ := gorm.Open("sqlite3", "/tmp/gorm2.db")
db.LogMode(true)
db.SingularTable(true)
//db.DropTable(&Account{})
//db.AutoMigrate(&Account{})
db.Model(Account{}).Updates(Account{Name: "hello"})
}
Output
test 鈿★笍 馃憠 $ go run main.go
(/Volumes/Sidekick/Users/vrparmar/Documents/workspace/src/bitbucket.org/vrparmar/test/main.go:21)
[2017-02-04 12:20:13] no such table: accounts
(/Volumes/Sidekick/Users/vrparmar/Documents/workspace/src/bitbucket.org/vrparmar/test/main.go:21)
[2017-02-04 12:20:13] [2.09ms] UPDATE "accounts" SET "name" = 'hello', "updated_at" = '2017-02-04T12:20:13-08:00' WHERE "accounts".deleted_at IS NULL
Hi @vrparmar
Thank you for your script, fixed that.
It works!!!
Thanks for quick response.
Most helpful comment
Can confirm I had this same problem today.
Code:
Produces:
no such table: accounts