(ctx context.Context, query *FileQuery, nodes []*Entity, init func(*Entity), assign func(*Entity, *File))
| 489 | } |
| 490 | |
| 491 | func (eq *EntityQuery) loadFile(ctx context.Context, query *FileQuery, nodes []*Entity, init func(*Entity), assign func(*Entity, *File)) error { |
| 492 | edgeIDs := make([]driver.Value, len(nodes)) |
| 493 | byID := make(map[int]*Entity) |
| 494 | nids := make(map[int]map[*Entity]struct{}) |
| 495 | for i, node := range nodes { |
| 496 | edgeIDs[i] = node.ID |
| 497 | byID[node.ID] = node |
| 498 | if init != nil { |
| 499 | init(node) |
| 500 | } |
| 501 | } |
| 502 | query.Where(func(s *sql.Selector) { |
| 503 | joinT := sql.Table(entity.FileTable) |
| 504 | s.Join(joinT).On(s.C(file.FieldID), joinT.C(entity.FilePrimaryKey[0])) |
| 505 | s.Where(sql.InValues(joinT.C(entity.FilePrimaryKey[1]), edgeIDs...)) |
| 506 | columns := s.SelectedColumns() |
| 507 | s.Select(joinT.C(entity.FilePrimaryKey[1])) |
| 508 | s.AppendSelect(columns...) |
| 509 | s.SetDistinct(false) |
| 510 | }) |
| 511 | if err := query.prepareQuery(ctx); err != nil { |
| 512 | return err |
| 513 | } |
| 514 | qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { |
| 515 | return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { |
| 516 | assign := spec.Assign |
| 517 | values := spec.ScanValues |
| 518 | spec.ScanValues = func(columns []string) ([]any, error) { |
| 519 | values, err := values(columns[1:]) |
| 520 | if err != nil { |
| 521 | return nil, err |
| 522 | } |
| 523 | return append([]any{new(sql.NullInt64)}, values...), nil |
| 524 | } |
| 525 | spec.Assign = func(columns []string, values []any) error { |
| 526 | outValue := int(values[0].(*sql.NullInt64).Int64) |
| 527 | inValue := int(values[1].(*sql.NullInt64).Int64) |
| 528 | if nids[inValue] == nil { |
| 529 | nids[inValue] = map[*Entity]struct{}{byID[outValue]: {}} |
| 530 | return assign(columns[1:], values[1:]) |
| 531 | } |
| 532 | nids[inValue][byID[outValue]] = struct{}{} |
| 533 | return nil |
| 534 | } |
| 535 | }) |
| 536 | }) |
| 537 | neighbors, err := withInterceptors[[]*File](ctx, query, qr, query.inters) |
| 538 | if err != nil { |
| 539 | return err |
| 540 | } |
| 541 | for _, n := range neighbors { |
| 542 | nodes, ok := nids[n.ID] |
| 543 | if !ok { |
| 544 | return fmt.Errorf(`unexpected "file" node returned %v`, n.ID) |
| 545 | } |
| 546 | for kn := range nodes { |
| 547 | assign(kn, n) |
| 548 | } |
no test coverage detected