Fix wrong comment (#2027)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2027 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
4499c8c5b5
commit
ad1a386b5e
|
@ -1045,3 +1045,43 @@ func TestUpdateFind(t *testing.T) {
|
||||||
err = session.Where("id = ?", tuf.Id).Find(&tufs)
|
err = session.Where("id = ?", tuf.Id).Find(&tufs)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFindAnonymousStruct(t *testing.T) {
|
||||||
|
type FindAnonymousStruct struct {
|
||||||
|
Id int64
|
||||||
|
Name string
|
||||||
|
Age int
|
||||||
|
IsMan bool
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, PrepareEngine())
|
||||||
|
assertSync(t, new(FindAnonymousStruct))
|
||||||
|
|
||||||
|
cnt, err := testEngine.Insert(&FindAnonymousStruct{
|
||||||
|
Name: "xlw",
|
||||||
|
Age: 42,
|
||||||
|
IsMan: true,
|
||||||
|
})
|
||||||
|
assert.EqualValues(t, 1, cnt)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
var findRes = make([]struct {
|
||||||
|
Id int64
|
||||||
|
Name string
|
||||||
|
}, 0)
|
||||||
|
err = testEngine.Table(new(FindAnonymousStruct)).Find(&findRes)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 1, len(findRes))
|
||||||
|
assert.EqualValues(t, 1, findRes[0].Id)
|
||||||
|
assert.EqualValues(t, "xlw", findRes[0].Name)
|
||||||
|
|
||||||
|
findRes = make([]struct {
|
||||||
|
Id int64
|
||||||
|
Name string
|
||||||
|
}, 0)
|
||||||
|
err = testEngine.Select("`id`,`name`").Table(new(FindAnonymousStruct)).Find(&findRes)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 1, len(findRes))
|
||||||
|
assert.EqualValues(t, 1, findRes[0].Id)
|
||||||
|
assert.EqualValues(t, "xlw", findRes[0].Name)
|
||||||
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ type ErrFieldIsNotExist struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrFieldIsNotExist) Error() string {
|
func (e ErrFieldIsNotExist) Error() string {
|
||||||
return fmt.Sprintf("field %s is not valid on table %s", e.FieldName, e.TableName)
|
return fmt.Sprintf("field %s is not exist on table %s", e.FieldName, e.TableName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrFieldIsNotValid is not valid
|
// ErrFieldIsNotValid is not valid
|
||||||
|
@ -677,10 +677,11 @@ func (session *Session) slice2Bean(scanResults []interface{}, fields []string, b
|
||||||
|
|
||||||
col, fieldValue, err := session.getField(dataStruct, table, colName, idx)
|
col, fieldValue, err := session.getField(dataStruct, table, colName, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(ErrFieldIsNotValid); !ok {
|
if _, ok := err.(ErrFieldIsNotExist); ok {
|
||||||
session.engine.logger.Warnf("%v", err)
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if fieldValue == nil {
|
if fieldValue == nil {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue