From f21e35f7c5f6a67cfcf54c0d439d9aef00224b77 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 26 Aug 2021 13:14:03 +0800 Subject: [PATCH] Fix table not supported error when using unexpected table name --- callbacks.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/callbacks.go b/callbacks.go index 02e741e7..7ab38926 100644 --- a/callbacks.go +++ b/callbacks.go @@ -102,8 +102,8 @@ func (p *processor) Execute(db *DB) *DB { // parse model values if stmt.Model != nil { - if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.SQL.Len() == 0)) { - if errors.Is(err, schema.ErrUnsupportedDataType) && stmt.Table == "" { + 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 == "" && stmt.TableExpr == nil { db.AddError(fmt.Errorf("%w: Table not set, please set it like: db.Model(&user) or db.Table(\"users\")", err)) } else { db.AddError(err)