add more test for join find (#922)
This commit is contained in:
parent
a491afac18
commit
ae0364a057
12
error.go
12
error.go
|
@ -26,10 +26,18 @@ var (
|
||||||
ErrNotImplemented = errors.New("Not implemented")
|
ErrNotImplemented = errors.New("Not implemented")
|
||||||
// ErrConditionType condition type unsupported
|
// ErrConditionType condition type unsupported
|
||||||
ErrConditionType = errors.New("Unsupported condition type")
|
ErrConditionType = errors.New("Unsupported condition type")
|
||||||
// ErrFieldIsNotExist columns does not exist
|
|
||||||
ErrFieldIsNotExist = errors.New("Field does not exist")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrFieldIsNotExist columns does not exist
|
||||||
|
type ErrFieldIsNotExist struct {
|
||||||
|
FieldName string
|
||||||
|
TableName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ErrFieldIsNotExist) Error() string {
|
||||||
|
return fmt.Sprintf("field %s is not valid on table %s", e.FieldName, e.TableName)
|
||||||
|
}
|
||||||
|
|
||||||
// ErrFieldIsNotValid is not valid
|
// ErrFieldIsNotValid is not valid
|
||||||
type ErrFieldIsNotValid struct {
|
type ErrFieldIsNotValid struct {
|
||||||
FieldName string
|
FieldName string
|
||||||
|
|
|
@ -281,7 +281,7 @@ func (session *Session) doPrepare(db *core.DB, sqlStr string) (stmt *core.Stmt,
|
||||||
func (session *Session) getField(dataStruct *reflect.Value, key string, table *core.Table, idx int) (*reflect.Value, error) {
|
func (session *Session) getField(dataStruct *reflect.Value, key string, table *core.Table, idx int) (*reflect.Value, error) {
|
||||||
var col *core.Column
|
var col *core.Column
|
||||||
if col = table.GetColumnIdx(key, idx); col == nil {
|
if col = table.GetColumnIdx(key, idx); col == nil {
|
||||||
return nil, ErrFieldIsNotExist
|
return nil, ErrFieldIsNotExist{key, table.Name}
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldValue, err := col.ValueOfV(dataStruct)
|
fieldValue, err := col.ValueOfV(dataStruct)
|
||||||
|
|
|
@ -770,7 +770,7 @@ func TestFindCacheLimit(t *testing.T) {
|
||||||
|
|
||||||
func TestFindJoin(t *testing.T) {
|
func TestFindJoin(t *testing.T) {
|
||||||
type SceneItem struct {
|
type SceneItem struct {
|
||||||
Type int
|
Type int
|
||||||
DeviceId int64
|
DeviceId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,4 +786,9 @@ func TestFindJoin(t *testing.T) {
|
||||||
err := testEngine.Join("LEFT OUTER", "device_user_privrels", "device_user_privrels.device_id=scene_item.device_id").
|
err := testEngine.Join("LEFT OUTER", "device_user_privrels", "device_user_privrels.device_id=scene_item.device_id").
|
||||||
Where("scene_item.type=?", 3).Or("device_user_privrels.user_id=?", 339).Find(&scenes)
|
Where("scene_item.type=?", 3).Or("device_user_privrels.user_id=?", 339).Find(&scenes)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
scenes = make([]SceneItem, 0)
|
||||||
|
err = testEngine.Join("LEFT OUTER", new(DeviceUserPrivrels), "device_user_privrels.device_id=scene_item.device_id").
|
||||||
|
Where("scene_item.type=?", 3).Or("device_user_privrels.user_id=?", 339).Find(&scenes)
|
||||||
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue