diff --git a/database/gdb/gdb_type_result_scanlist.go b/database/gdb/gdb_type_result_scanlist.go index ba023131c..3b4a41648 100644 --- a/database/gdb/gdb_type_result_scanlist.go +++ b/database/gdb/gdb_type_result_scanlist.go @@ -32,11 +32,15 @@ import ( // ScanList(&users, "User") // ScanList(&users, "UserDetail", "User", "uid:Uid") // ScanList(&users, "UserScores", "User", "uid:Uid") +// // The parameters "User"/"UserDetail"/"UserScores" in the example codes specify the target attribute struct // that current result will be bound to. +// // The "uid" in the example codes is the table field name of the result, and the "Uid" is the relational -// struct attribute name. It automatically calculates the HasOne/HasMany relationship with given -// parameter. +// struct attribute name - not the attribute name of the bound to target. In the example codes, it's attribute +// name "Uid" of "User" of entity "Entity". It automatically calculates the HasOne/HasMany relationship with +// given parameter. +// // See the example or unit testing cases for clear understanding for this function. func (r Result) ScanList(listPointer interface{}, attributeName string, relation ...string) (err error) { // Necessary checks for parameters. diff --git a/database/gdb/gdb_z_mysql_relation_test.go b/database/gdb/gdb_z_mysql_relation_test.go index 1ac691364..df45451e1 100644 --- a/database/gdb/gdb_z_mysql_relation_test.go +++ b/database/gdb/gdb_z_mysql_relation_test.go @@ -66,9 +66,9 @@ CREATE TABLE %s ( Address string `json:"address"` } type EntityUserScores struct { - Id int `json:"id"` - UserId int `json:"uid"` - Score int `json:"score"` + Id int `json:"id"` + Uid int `json:"uid"` + Score int `json:"score"` } type Entity struct { User *EntityUser @@ -144,10 +144,10 @@ CREATE TABLE %s ( t.Assert(err, nil) t.Assert(len(users[0].UserScores), 5) t.Assert(len(users[1].UserScores), 5) - t.Assert(users[0].UserScores[0].UserId, 3) + t.Assert(users[0].UserScores[0].Uid, 3) t.Assert(users[0].UserScores[0].Score, 1) t.Assert(users[0].UserScores[4].Score, 5) - t.Assert(users[1].UserScores[0].UserId, 4) + t.Assert(users[1].UserScores[0].Uid, 4) t.Assert(users[1].UserScores[0].Score, 1) t.Assert(users[1].UserScores[4].Score, 5) }) @@ -177,10 +177,10 @@ CREATE TABLE %s ( t.Assert(err, nil) t.Assert(len(users[0].UserScores), 5) t.Assert(len(users[1].UserScores), 5) - t.Assert(users[0].UserScores[0].UserId, 3) + t.Assert(users[0].UserScores[0].Uid, 3) t.Assert(users[0].UserScores[0].Score, 1) t.Assert(users[0].UserScores[4].Score, 5) - t.Assert(users[1].UserScores[0].UserId, 4) + t.Assert(users[1].UserScores[0].Uid, 4) t.Assert(users[1].UserScores[0].Score, 1) t.Assert(users[1].UserScores[4].Score, 5) })