(t *testing.T)
| 290 | } |
| 291 | |
| 292 | func TestSetNeighbors(t *testing.T) { |
| 293 | tests := []struct { |
| 294 | name string |
| 295 | input *Step |
| 296 | wantQuery string |
| 297 | wantArgs []any |
| 298 | }{ |
| 299 | { |
| 300 | name: "O2M/2types", |
| 301 | input: NewStep( |
| 302 | From("users", "id", sql.Select().From(sql.Table("users")).Where(sql.EQ("name", "a8m"))), |
| 303 | To("pets", "id"), |
| 304 | Edge(O2M, false, "users", "owner_id"), |
| 305 | ), |
| 306 | wantQuery: `SELECT * FROM "pets" JOIN (SELECT "users"."id" FROM "users" WHERE "name" = $1) AS "t1" ON "pets"."owner_id" = "t1"."id"`, |
| 307 | wantArgs: []any{"a8m"}, |
| 308 | }, |
| 309 | { |
| 310 | name: "M2O/2types", |
| 311 | input: NewStep( |
| 312 | From("pets", "id", sql.Select().From(sql.Table("pets")).Where(sql.EQ("name", "pedro"))), |
| 313 | To("users", "id"), |
| 314 | Edge(M2O, true, "pets", "owner_id"), |
| 315 | ), |
| 316 | wantQuery: `SELECT * FROM "users" JOIN (SELECT "pets"."owner_id" FROM "pets" WHERE "name" = $1) AS "t1" ON "users"."id" = "t1"."owner_id"`, |
| 317 | wantArgs: []any{"pedro"}, |
| 318 | }, |
| 319 | { |
| 320 | name: "M2M/2types", |
| 321 | input: NewStep( |
| 322 | From("users", "id", sql.Select().From(sql.Table("users")).Where(sql.EQ("name", "a8m"))), |
| 323 | To("groups", "id"), |
| 324 | Edge(M2M, false, "user_groups", "user_id", "group_id"), |
| 325 | ), |
| 326 | wantQuery: ` |
| 327 | SELECT * |
| 328 | FROM "groups" |
| 329 | JOIN |
| 330 | (SELECT "user_groups"."group_id" |
| 331 | FROM "user_groups" |
| 332 | JOIN |
| 333 | (SELECT "users"."id" |
| 334 | FROM "users" |
| 335 | WHERE "name" = $1) AS "t1" ON "user_groups"."user_id" = "t1"."id") AS "t1" ON "groups"."id" = "t1"."group_id"`, |
| 336 | wantArgs: []any{"a8m"}, |
| 337 | }, |
| 338 | { |
| 339 | name: "M2M/2types/inverse", |
| 340 | input: NewStep( |
| 341 | From("groups", "id", sql.Select().From(sql.Table("groups")).Where(sql.EQ("name", "GitHub"))), |
| 342 | To("users", "id"), |
| 343 | Edge(M2M, true, "user_groups", "user_id", "group_id"), |
| 344 | ), |
| 345 | wantQuery: ` |
| 346 | SELECT * |
| 347 | FROM "users" |
| 348 | JOIN |
| 349 | (SELECT "user_groups"."user_id" |
nothing calls this directly
no test coverage detected
searching dependent graphs…