Fix table not supported error when using unexpected table name

This commit is contained in:
Jinzhu 2021-08-26 13:14:03 +08:00
parent 0934b10856
commit f21e35f7c5
1 changed files with 2 additions and 2 deletions

View File

@ -102,8 +102,8 @@ func (p *processor) Execute(db *DB) *DB {
// parse model values // parse model values
if stmt.Model != nil { if stmt.Model != nil {
if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.SQL.Len() == 0)) { if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.TableExpr == nil && stmt.SQL.Len() == 0)) {
if errors.Is(err, schema.ErrUnsupportedDataType) && stmt.Table == "" { if errors.Is(err, schema.ErrUnsupportedDataType) && stmt.Table == "" && stmt.TableExpr == nil {
db.AddError(fmt.Errorf("%w: Table not set, please set it like: db.Model(&user) or db.Table(\"users\")", err)) db.AddError(fmt.Errorf("%w: Table not set, please set it like: db.Model(&user) or db.Table(\"users\")", err))
} else { } else {
db.AddError(err) db.AddError(err)