MCPcopy Index your code
hub / github.com/ent/ent / HasNeighbors

Function HasNeighbors

dialect/sql/sqlgraph/graph.go:240–277  ·  view source on GitHub ↗

HasNeighbors applies on the given Selector a neighbors check.

(q *sql.Selector, s *Step)

Source from the content-addressed store, hash-verified

238
239// HasNeighbors applies on the given Selector a neighbors check.
240func HasNeighbors(q *sql.Selector, s *Step) {
241 builder := sql.Dialect(q.Dialect())
242 switch {
243 case s.ThroughEdgeTable():
244 pk1 := s.Edge.Columns[0]
245 if s.Edge.Inverse {
246 pk1 = s.Edge.Columns[1]
247 }
248 join := builder.Table(s.Edge.Table).Schema(s.Edge.Schema)
249 q.Where(
250 sql.In(
251 q.C(s.From.Column),
252 builder.Select(join.C(pk1)).From(join),
253 ),
254 )
255 case s.FromEdgeOwner():
256 q.Where(sql.NotNull(q.C(s.Edge.Columns[0])))
257 case s.ToEdgeOwner():
258 to := builder.Table(s.Edge.Table).Schema(s.Edge.Schema)
259 // In case the edge reside on the same table, give
260 // the edge an alias to make qualifier different.
261 if s.From.Table == s.Edge.Table {
262 to.As(fmt.Sprintf("%s_edge", s.Edge.Table))
263 }
264 q.Where(
265 sql.Exists(
266 builder.Select(to.C(s.Edge.Columns[0])).
267 From(to).
268 Where(
269 sql.ColumnsEQ(
270 q.C(s.From.Column),
271 to.C(s.Edge.Columns[0]),
272 ),
273 ),
274 ),
275 )
276 }
277}
278
279// HasNeighborsWith applies on the given Selector a neighbors check.
280// The given predicate applies its filtering on the selector.

Callers 15

HasAdminsFunction · 0.92
HasCarFunction · 0.92
HasPetsFunction · 0.92
HasFriendsFunction · 0.92
HasOwnerFunction · 0.92
HasOwnerFunction · 0.92
HasParentFunction · 0.92
HasChildrenFunction · 0.92
HasSpouseFunction · 0.92
HasCarFunction · 0.92
HasOwnerFunction · 0.92
HasCardFunction · 0.92

Calls 15

DialectFunction · 0.92
InFunction · 0.92
NotNullFunction · 0.92
ExistsFunction · 0.92
ColumnsEQFunction · 0.92
ThroughEdgeTableMethod · 0.80
FromEdgeOwnerMethod · 0.80
ToEdgeOwnerMethod · 0.80
DialectMethod · 0.65
WhereMethod · 0.65
CMethod · 0.65
SchemaMethod · 0.45

Tested by 1

TestHasNeighborsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…