Fix find alias bug

This commit is contained in:
Lunny Xiao 2020-03-08 09:48:25 +08:00
parent 257653726e
commit a6e4092b3b
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 19 additions and 5 deletions

View File

@ -35,9 +35,8 @@ var (
// Statement save all the sql info for executing SQL // Statement save all the sql info for executing SQL
type Statement struct { type Statement struct {
RefTable *schemas.Table RefTable *schemas.Table
dialect dialects.Dialect dialect dialects.Dialect
//Engine *Engine
defaultTimeZone *time.Location defaultTimeZone *time.Location
tagParser *tags.Parser tagParser *tags.Parser
Start int Start int
@ -985,8 +984,13 @@ func (statement *Statement) joinColumns(cols []*schemas.Column, includeTableName
func (statement *Statement) CondDeleted(col *schemas.Column) builder.Cond { func (statement *Statement) CondDeleted(col *schemas.Column) builder.Cond {
var colName = col.Name var colName = col.Name
if statement.JoinStr != "" { if statement.JoinStr != "" {
colName = statement.quote(statement.TableName()) + var prefix string
"." + statement.quote(col.Name) if statement.TableAlias != "" {
prefix = statement.TableAlias
} else {
prefix = statement.TableName()
}
colName = statement.quote(prefix) + "." + statement.quote(col.Name)
} }
var cond = builder.NewCond() var cond = builder.NewCond()
if col.SQLType.IsNumeric() { if col.SQLType.IsNumeric() {

View File

@ -794,6 +794,16 @@ func TestMoreExtends(t *testing.T) {
Limit(10, 10). Limit(10, 10).
Find(&books) Find(&books)
assert.NoError(t, err) assert.NoError(t, err)
books = make([]MoreExtendsBooksExtend, 0, len(books))
err = testEngine.Table("more_extends_books").
Alias("m").
Select("m.*, more_extends_users.*").
Join("INNER", "more_extends_users", "m.user_id = more_extends_users.id").
Where("m.name LIKE ?", "abc").
Limit(10, 10).
Find(&books)
assert.NoError(t, err)
} }
func TestDistinctAndCols(t *testing.T) { func TestDistinctAndCols(t *testing.T) {