MCPcopy
hub / github.com/ent/ent / OrderByNeighborTerms

Function OrderByNeighborTerms

dialect/sql/sqlgraph/graph.go:522–560  ·  view source on GitHub ↗

OrderByNeighborTerms appends ordering based on the number of neighbors. For example, order users by their number of posts.

(q *sql.Selector, s *Step, opts ...sql.OrderTerm)

Source from the content-addressed store, hash-verified

520// OrderByNeighborTerms appends ordering based on the number of neighbors.
521// For example, order users by their number of posts.
522func OrderByNeighborTerms(q *sql.Selector, s *Step, opts ...sql.OrderTerm) {
523 var (
524 join *sql.Selector
525 build = sql.Dialect(q.Dialect())
526 )
527 switch {
528 case s.FromEdgeOwner():
529 toT := build.Table(s.To.Table).Schema(s.To.Schema)
530 join = build.Select(toT.C(s.To.Column)).
531 From(toT)
532 selectTerms(join, opts)
533 q.LeftJoin(join).
534 On(q.C(s.Edge.Columns[0]), join.C(s.To.Column))
535 case s.ThroughEdgeTable():
536 pk1, pk2 := s.Edge.Columns[1], s.Edge.Columns[0]
537 if s.Edge.Inverse {
538 pk1, pk2 = pk2, pk1
539 }
540 toT := build.Table(s.To.Table).Schema(s.To.Schema)
541 joinT := build.Table(s.Edge.Table).Schema(s.Edge.Schema)
542 join = build.Select(pk2).
543 From(toT).
544 Join(joinT).
545 On(toT.C(s.To.Column), joinT.C(pk1)).
546 GroupBy(pk2)
547 selectTerms(join, opts)
548 q.LeftJoin(join).
549 On(q.C(s.From.Column), join.C(pk2))
550 case s.ToEdgeOwner():
551 toT := build.Table(s.Edge.Table).Schema(s.Edge.Schema)
552 join = build.Select(toT.C(s.Edge.Columns[0])).
553 From(toT).
554 GroupBy(toT.C(s.Edge.Columns[0]))
555 selectTerms(join, opts)
556 q.LeftJoin(join).
557 On(q.C(s.From.Column), join.C(s.Edge.Columns[0]))
558 }
559 orderTerms(q, join, opts)
560}
561
562// NeighborsLimit provides a modifier function that limits the
563// number of neighbors (rows) loaded per parent row (node).

Callers 15

OrderByEdgeTermsFunction · 0.92
ByAdminsFunction · 0.92
ByCarFunction · 0.92
ByPetsFieldFunction · 0.92
ByFriendsFunction · 0.92
ByOwnerFieldFunction · 0.92
ByOwnerFieldFunction · 0.92
ByParentFieldFunction · 0.92
ByChildrenFunction · 0.92
BySpouseFieldFunction · 0.92
ByCarFieldFunction · 0.92
ByOwnerFieldFunction · 0.92

Calls 15

DialectFunction · 0.92
selectTermsFunction · 0.85
orderTermsFunction · 0.85
FromEdgeOwnerMethod · 0.80
OnMethod · 0.80
LeftJoinMethod · 0.80
ThroughEdgeTableMethod · 0.80
ToEdgeOwnerMethod · 0.80
DialectMethod · 0.65
CMethod · 0.65
SchemaMethod · 0.45
TableMethod · 0.45

Tested by 2

OrderByEdgeTermsFunction · 0.74
TestOrderByNeighborTermsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…