mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: move set-neighbors logic from codegen to sqlgraph
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/183 Reviewed By: alexsn Differential Revision: D18644179 fbshipit-source-id: 2f2b0c03811a09c4c11240e5161187afbb2ac553
This commit is contained in:
committed by
Facebook Github Bot
parent
1e49561634
commit
c355ed49be
@@ -56,20 +56,17 @@ func (uq *UserQuery) Order(o ...Order) *UserQuery {
|
||||
// QueryFriends chains the current query on the friends edge.
|
||||
func (uq *UserQuery) QueryFriends() *UserQuery {
|
||||
query := &UserQuery{config: uq.config}
|
||||
|
||||
builder := sql.Dialect(uq.driver.Dialect())
|
||||
t1 := builder.Table(user.Table)
|
||||
t2 := uq.sqlQuery()
|
||||
t2.Select(t2.C(user.FieldID))
|
||||
t3 := builder.Table(user.FriendsTable)
|
||||
t4 := builder.Select(t3.C(user.FriendsPrimaryKey[1])).
|
||||
From(t3).
|
||||
Join(t2).
|
||||
On(t3.C(user.FriendsPrimaryKey[0]), t2.C(user.FieldID))
|
||||
query.sql = builder.Select().
|
||||
From(t1).
|
||||
Join(t4).
|
||||
On(t1.C(user.FieldID), t4.C(user.FriendsPrimaryKey[1]))
|
||||
step := &sql.Step{}
|
||||
step.From.V = uq.sqlQuery()
|
||||
step.From.Table = user.Table
|
||||
step.From.Column = user.FieldID
|
||||
step.To.Table = user.Table
|
||||
step.To.Column = user.FieldID
|
||||
step.Edge.Rel = sql.M2M
|
||||
step.Edge.Inverse = false
|
||||
step.Edge.Table = user.FriendsTable
|
||||
step.Edge.Columns = append(step.Edge.Columns, user.FriendsPrimaryKey...)
|
||||
query.sql = sql.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return query
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user