MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _get_leftmost

Method _get_leftmost

lib/sqlalchemy/orm/strategies.py:1490–1537  ·  view source on GitHub ↗
(
        self,
        orig_query_entity_index,
        subq_path,
        current_compile_state,
        is_root,
    )

Source from the content-addressed store, hash-verified

1488 ).init_class_attribute(mapper)
1489
1490 def _get_leftmost(
1491 self,
1492 orig_query_entity_index,
1493 subq_path,
1494 current_compile_state,
1495 is_root,
1496 ):
1497 given_subq_path = subq_path
1498 subq_path = subq_path.path
1499 subq_mapper = orm_util._class_to_mapper(subq_path[0])
1500
1501 # determine attributes of the leftmost mapper
1502 if (
1503 self.parent.isa(subq_mapper)
1504 and self.parent_property is subq_path[1]
1505 ):
1506 leftmost_mapper, leftmost_prop = self.parent, self.parent_property
1507 else:
1508 leftmost_mapper, leftmost_prop = subq_mapper, subq_path[1]
1509
1510 if is_root:
1511 # the subq_path is also coming from cached state, so when we start
1512 # building up this path, it has to also be converted to be in terms
1513 # of the current state. this is for the specific case of the entity
1514 # is an AliasedClass against a subquery that's not otherwise going
1515 # to adapt
1516 new_subq_path = current_compile_state._entities[
1517 orig_query_entity_index
1518 ].entity_zero._path_registry[leftmost_prop]
1519 additional = len(subq_path) - len(new_subq_path)
1520 if additional:
1521 new_subq_path += path_registry.PathRegistry.coerce(
1522 subq_path[-additional:]
1523 )
1524 else:
1525 new_subq_path = given_subq_path
1526
1527 leftmost_cols = leftmost_prop.local_columns
1528
1529 leftmost_attr = [
1530 getattr(
1531 new_subq_path.path[0].entity,
1532 leftmost_mapper._columntoproperty[c].key,
1533 )
1534 for c in leftmost_cols
1535 ]
1536
1537 return leftmost_mapper, leftmost_attr, leftmost_prop, new_subq_path
1538
1539 def _generate_from_original_query(
1540 self,

Callers 1

Calls 2

isaMethod · 0.80
coerceMethod · 0.45

Tested by

no test coverage detected