MCPcopy
hub / github.com/ent/ent / TestHasNeighborsWith

Function TestHasNeighborsWith

dialect/sql/sqlgraph/graph_test.go:638–886  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

636}
637
638func TestHasNeighborsWith(t *testing.T) {
639 tests := []struct {
640 name string
641 step *Step
642 selector *sql.Selector
643 predicate func(*sql.Selector)
644 wantQuery string
645 wantArgs []any
646 }{
647 {
648 name: "O2O",
649 step: NewStep(
650 From("users", "id"),
651 To("cards", "id"),
652 Edge(O2O, false, "cards", "owner_id"),
653 ),
654 selector: sql.Dialect("postgres").Select("*").From(sql.Table("users")),
655 predicate: func(s *sql.Selector) {
656 s.Where(sql.EQ("expired", false))
657 },
658 wantQuery: `SELECT * FROM "users" WHERE EXISTS (SELECT "cards"."owner_id" FROM "cards" WHERE "users"."id" = "cards"."owner_id" AND NOT "expired")`,
659 },
660 {
661 name: "O2O/inverse",
662 step: NewStep(
663 From("cards", "id"),
664 To("users", "id"),
665 Edge(O2O, true, "cards", "owner_id"),
666 ),
667 selector: sql.Dialect("postgres").Select("*").From(sql.Table("cards")),
668 predicate: func(s *sql.Selector) {
669 s.Where(sql.EQ("name", "a8m"))
670 },
671 wantQuery: `SELECT * FROM "cards" WHERE EXISTS (SELECT "users"."id" FROM "users" WHERE "cards"."owner_id" = "users"."id" AND "name" = $1)`,
672 wantArgs: []any{"a8m"},
673 },
674 {
675 name: "O2M",
676 step: NewStep(
677 From("users", "id"),
678 To("pets", "id"),
679 Edge(O2M, false, "pets", "owner_id"),
680 ),
681 selector: sql.Dialect("postgres").Select("*").
682 From(sql.Table("users")).
683 Where(sql.EQ("last_name", "mashraki")),
684 predicate: func(s *sql.Selector) {
685 s.Where(sql.EQ("name", "pedro"))
686 },
687 wantQuery: `SELECT * FROM "users" WHERE "last_name" = $1 AND EXISTS (SELECT "pets"."owner_id" FROM "pets" WHERE "users"."id" = "pets"."owner_id" AND "name" = $2)`,
688 wantArgs: []any{"mashraki", "pedro"},
689 },
690 {
691 name: "M2O",
692 step: NewStep(
693 From("pets", "id"),
694 To("users", "id"),
695 Edge(M2O, true, "pets", "owner_id"),

Callers

nothing calls this directly

Calls 15

DialectFunction · 0.92
TableFunction · 0.92
EQFunction · 0.92
AndFunction · 0.92
NotNullFunction · 0.92
SelectFunction · 0.92
NewStepFunction · 0.85
HasNeighborsWithFunction · 0.85
RunMethod · 0.80
FromFunction · 0.70
ToFunction · 0.70
EdgeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…