MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _create_eager_join

Method _create_eager_join

lib/sqlalchemy/orm/strategies.py:2445–2599  ·  view source on GitHub ↗
(
        self,
        compile_state,
        query_entity,
        path,
        adapter,
        parentmapper,
        clauses,
        innerjoin,
        chained_from_outerjoin,
        extra_criteria,
    )

Source from the content-addressed store, hash-verified

2443 return clauses, adapter, add_to_collection, chained_from_outerjoin
2444
2445 def _create_eager_join(
2446 self,
2447 compile_state,
2448 query_entity,
2449 path,
2450 adapter,
2451 parentmapper,
2452 clauses,
2453 innerjoin,
2454 chained_from_outerjoin,
2455 extra_criteria,
2456 ):
2457 if parentmapper is None:
2458 localparent = query_entity.mapper
2459 else:
2460 localparent = parentmapper
2461
2462 # whether or not the Query will wrap the selectable in a subquery,
2463 # and then attach eager load joins to that (i.e., in the case of
2464 # LIMIT/OFFSET etc.)
2465 should_nest_selectable = compile_state._should_nest_selectable
2466
2467 query_entity_key = None
2468
2469 if (
2470 query_entity not in compile_state.eager_joins
2471 and not should_nest_selectable
2472 and compile_state.from_clauses
2473 ):
2474 indexes = sql_util.find_left_clause_that_matches_given(
2475 compile_state.from_clauses, query_entity.selectable
2476 )
2477
2478 if len(indexes) > 1:
2479 # for the eager load case, I can't reproduce this right
2480 # now. For query.join() I can.
2481 raise sa_exc.InvalidRequestError(
2482 "Can't identify which query entity in which to joined "
2483 "eager load from. Please use an exact match when "
2484 "specifying the join path."
2485 )
2486
2487 if indexes:
2488 clause = compile_state.from_clauses[indexes[0]]
2489 # join to an existing FROM clause on the query.
2490 # key it to its list index in the eager_joins dict.
2491 # Query._compile_context will adapt as needed and
2492 # append to the FROM clause of the select().
2493 query_entity_key, default_towrap = indexes[0], clause
2494
2495 if query_entity_key is None:
2496 query_entity_key, default_towrap = (
2497 query_entity,
2498 query_entity.selectable,
2499 )
2500
2501 towrap = compile_state.eager_joins.setdefault(
2502 query_entity_key, default_towrap

Callers

nothing calls this directly

Calls 8

_entity_for_mapperMethod · 0.80
isaMethod · 0.80
setdefaultMethod · 0.45
getMethod · 0.45
contains_columnMethod · 0.45

Tested by

no test coverage detected