// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package gdb_test import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/test/gtest" "testing" ) func Test_Model_WherePrefix(t *testing.T) { var ( table1 = gtime.TimestampNanoStr() + "_table1" table2 = gtime.TimestampNanoStr() + "_table2" ) createInitTable(table1) defer dropTable(table1) createInitTable(table2) defer dropTable(table2) gtest.C(t, func(t *gtest.T) { r, err := db.Model(table1). FieldsPrefix(table1, "*"). LeftJoinOnField(table2, "id"). WherePrefix(table2, g.Map{ "id": g.Slice{1, 2}, }). Order("id asc").All() t.AssertNil(err) t.Assert(len(r), 2) t.Assert(r[0]["id"], "1") t.Assert(r[1]["id"], "2") }) } func Test_Model_WhereOrPrefix(t *testing.T) { var ( table1 = gtime.TimestampNanoStr() + "_table1" table2 = gtime.TimestampNanoStr() + "_table2" ) createInitTable(table1) defer dropTable(table1) createInitTable(table2) defer dropTable(table2) gtest.C(t, func(t *gtest.T) { r, err := db.Model(table1). FieldsPrefix(table1, "*"). LeftJoinOnField(table2, "id"). WhereOrPrefix(table1, g.Map{ "id": g.Slice{1, 2}, }). WhereOrPrefix(table2, g.Map{ "id": g.Slice{8, 9}, }). Order("id asc").All() t.AssertNil(err) t.Assert(len(r), 4) t.Assert(r[0]["id"], "1") t.Assert(r[1]["id"], "2") t.Assert(r[2]["id"], "8") t.Assert(r[3]["id"], "9") }) }