(
self, parent: _AbstractEntityRegistry, prop: StrategizedProperty[Any]
)
| 541 | entity: Optional[_InternalEntityType[Any]] |
| 542 | |
| 543 | def __init__( |
| 544 | self, parent: _AbstractEntityRegistry, prop: StrategizedProperty[Any] |
| 545 | ): |
| 546 | |
| 547 | # restate this path in terms of the |
| 548 | # given StrategizedProperty's parent. |
| 549 | insp = cast("_InternalEntityType[Any]", parent[-1]) |
| 550 | natural_parent: _AbstractEntityRegistry = parent |
| 551 | |
| 552 | # inherit "is_unnatural" from the parent |
| 553 | self.is_unnatural = parent.parent.is_unnatural or bool( |
| 554 | parent.mapper.inherits |
| 555 | ) |
| 556 | |
| 557 | if not insp.is_aliased_class or insp._use_mapper_path: # type: ignore |
| 558 | parent = natural_parent = parent.parent[prop.parent] |
| 559 | elif ( |
| 560 | insp.is_aliased_class |
| 561 | and insp.with_polymorphic_mappers |
| 562 | and prop.parent in insp.with_polymorphic_mappers |
| 563 | ): |
| 564 | subclass_entity: _InternalEntityType[Any] = parent[-1]._entity_for_mapper(prop.parent) # type: ignore # noqa: E501 |
| 565 | parent = parent.parent[subclass_entity] |
| 566 | |
| 567 | # when building a path where with_polymorphic() is in use, |
| 568 | # special logic to determine the "natural path" when subclass |
| 569 | # entities are used. |
| 570 | # |
| 571 | # here we are trying to distinguish between a path that starts |
| 572 | # on a with_polymorphic entity vs. one that starts on a |
| 573 | # normal entity that introduces a with_polymorphic() in the |
| 574 | # middle using of_type(): |
| 575 | # |
| 576 | # # as in test_polymorphic_rel-> |
| 577 | # # test_subqueryload_on_subclass_uses_path_correctly |
| 578 | # wp = with_polymorphic(RegularEntity, "*") |
| 579 | # sess.query(wp).options(someload(wp.SomeSubEntity.foos)) |
| 580 | # |
| 581 | # vs |
| 582 | # |
| 583 | # # as in test_relationship->JoinedloadWPolyOfTypeContinued |
| 584 | # wp = with_polymorphic(SomeFoo, "*") |
| 585 | # sess.query(RegularEntity).options( |
| 586 | # someload(RegularEntity.foos.of_type(wp)) |
| 587 | # .someload(wp.SubFoo.bar) |
| 588 | # ) |
| 589 | # |
| 590 | # in the former case, the Query as it generates a path that we |
| 591 | # want to match will be in terms of the with_polymorphic at the |
| 592 | # beginning. in the latter case, Query will generate simple |
| 593 | # paths that don't know about this with_polymorphic, so we must |
| 594 | # use a separate natural path. |
| 595 | # |
| 596 | # |
| 597 | if parent.parent: |
| 598 | natural_parent = parent.parent[subclass_entity.mapper] |
| 599 | self.is_unnatural = True |
| 600 | else: |
nothing calls this directly
no test coverage detected