Skip to content

Commit

Permalink
Fix find with another struct
Browse files Browse the repository at this point in the history
  • Loading branch information
xormplus committed Apr 30, 2020
1 parent 2f364d8 commit 96878f0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions integrations/session_find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,13 @@ func TestFindExtends(t *testing.T) {
err = testEngine.Find(&results)
assert.NoError(t, err)
assert.EqualValues(t, 2, len(results))

results = make([]FindExtendsA, 0, 2)
err = testEngine.Find(&results, &FindExtendsB{
ID: 1,
})
assert.NoError(t, err)
assert.EqualValues(t, 1, len(results))
}

func TestFindExtends3(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion internal/statements/pk.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (statement *Statement) ProcessIDParam() error {
}

if len(statement.RefTable.PrimaryKeys) != len(statement.idParam) {
fmt.Println("=====", statement.RefTable.PrimaryKeys, statement.idParam)
return fmt.Errorf("ID condition is error, expect %d primarykeys, there are %d",
len(statement.RefTable.PrimaryKeys),
len(statement.idParam),
Expand Down
7 changes: 5 additions & 2 deletions session_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
)
if tp == tpStruct {
if !session.statement.NoAutoCondition && len(condiBean) > 0 {
var err error
autoCond, err = session.statement.BuildConds(table, condiBean[0], true, true, false, true, addedTableName)
condTable, err := session.engine.tagParser.Parse(reflect.ValueOf(condiBean[0]))
if err != nil {
return err
}
autoCond, err = session.statement.BuildConds(condTable, condiBean[0], true, true, false, true, addedTableName)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions tags/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (parser *Parser) Parse(v reflect.Value) (*schemas.Table, error) {
t := v.Type()
if t.Kind() == reflect.Ptr {
t = t.Elem()
v = v.Elem()
}
if t.Kind() != reflect.Struct {
return nil, ErrUnsupportedType
Expand Down
2 changes: 1 addition & 1 deletion xorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

const (
// Version show the xorm's version
Version string = "0.8.0.0330"
Version string = "1.0.1.0430"
)

func close(engine *Engine) {
Expand Down

0 comments on commit 96878f0

Please sign in to comment.