dialect/sql: add neighbors test for O2O with 2 types

Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/146

Reviewed By: idoshveki

Differential Revision: D18369884

fbshipit-source-id: 8cba47de27831d317dbe438ccff49b61132f6085
This commit is contained in:
Ariel Mashraki
2019-11-07 02:41:14 -08:00
committed by Facebook Github Bot
parent 6eb14bba9f
commit 0ff49fe89f

View File

@@ -71,6 +71,41 @@ func TestNeighbors(t *testing.T) {
wantQuery: "SELECT * FROM `users` WHERE `parent_id` = ?",
wantArgs: []interface{}{1},
},
{
name: "O2O/2types",
input: func() *Step {
step := &Step{}
step.From.V = 2
step.From.Table = "users"
step.From.Column = "id"
step.To.Table = "card"
step.To.Column = "id"
step.Edge.Rel = O2O
step.Edge.Table = "cards"
step.Edge.Columns = []string{"owner_id"}
return step
}(),
wantQuery: "SELECT * FROM `card` WHERE `owner_id` = ?",
wantArgs: []interface{}{2},
},
{
name: "O2O/2types/inverse",
input: func() *Step {
step := &Step{}
step.From.V = 2
step.From.Table = "card"
step.From.Column = "id"
step.To.Table = "users"
step.To.Column = "id"
step.Edge.Rel = O2O
step.Edge.Table = "cards"
step.Edge.Inverse = true
step.Edge.Columns = []string{"owner_id"}
return step
}(),
wantQuery: "SELECT * FROM `users` JOIN (SELECT `owner_id` FROM `cards` WHERE `id` = ?) AS `t1` ON `users`.`id` = `t1`.`owner_id`",
wantArgs: []interface{}{2},
},
{
name: "O2M/2types",
input: func() *Step {