Skip to content

Commit

Permalink
fix: has many relationship with multiple columns
Browse files Browse the repository at this point in the history
  • Loading branch information
bgertsberg11 committed Oct 31, 2024
1 parent 1bb5597 commit 1664b2c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions model_table_has_many.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ 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()
} else {
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
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 1664b2c

Please sign in to comment.