summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/model_table_has_many.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/uptrace/bun/model_table_has_many.go')
-rw-r--r--vendor/github.com/uptrace/bun/model_table_has_many.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/vendor/github.com/uptrace/bun/model_table_has_many.go b/vendor/github.com/uptrace/bun/model_table_has_many.go
index 544cdf5d6..cd721a1b2 100644
--- a/vendor/github.com/uptrace/bun/model_table_has_many.go
+++ b/vendor/github.com/uptrace/bun/model_table_has_many.go
@@ -51,7 +51,7 @@ func (m *hasManyModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, error
dest := makeDest(m, len(columns))
var n int
-
+ m.structKey = make([]interface{}, len(m.rel.JoinPKs))
for rows.Next() {
if m.sliceOfPtr {
m.strct = reflect.New(m.table.Type).Elem()
@@ -59,9 +59,8 @@ func (m *hasManyModel) ScanRows(ctx context.Context, rows *sql.Rows) (int, error
m.strct.Set(m.table.ZeroValue)
}
m.structInited = false
-
m.scanIndex = 0
- m.structKey = m.structKey[:0]
+
if err := rows.Scan(dest...); err != nil {
return 0, err
}
@@ -92,9 +91,9 @@ func (m *hasManyModel) Scan(src interface{}) error {
return err
}
- for _, f := range m.rel.JoinPKs {
- if f.Name == field.Name {
- m.structKey = append(m.structKey, indirectFieldValue(field.Value(m.strct)))
+ for i, f := range m.rel.JoinPKs {
+ if f.Name == column {
+ m.structKey[i] = indirectFieldValue(field.Value(m.strct))
break
}
}