MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / join_targets

Method join_targets

lib/sqlalchemy/orm/relationships.py:3256–3399  ·  view source on GitHub ↗

Given a source and destination selectable, create a join between them. This takes into account aliasing the join clause to reference the appropriate corresponding columns in the target objects, as well as the extra child criterion, equivalent column sets, etc

(
        self,
        source_selectable: Optional[FromClause],
        dest_selectable: FromClause,
        aliased: bool,
        single_crit: Optional[ColumnElement[bool]] = None,
        extra_criteria: Tuple[ColumnElement[bool], ...] = (),
    )

Source from the content-addressed store, hash-verified

3254 return util.EMPTY_SET
3255
3256 def join_targets(
3257 self,
3258 source_selectable: Optional[FromClause],
3259 dest_selectable: FromClause,
3260 aliased: bool,
3261 single_crit: Optional[ColumnElement[bool]] = None,
3262 extra_criteria: Tuple[ColumnElement[bool], ...] = (),
3263 ) -> Tuple[
3264 ColumnElement[bool],
3265 Optional[ColumnElement[bool]],
3266 Optional[FromClause],
3267 Optional[ClauseAdapter],
3268 FromClause,
3269 ]:
3270 """Given a source and destination selectable, create a
3271 join between them.
3272
3273 This takes into account aliasing the join clause
3274 to reference the appropriate corresponding columns
3275 in the target objects, as well as the extra child
3276 criterion, equivalent column sets, etc.
3277
3278 """
3279 # place a barrier on the destination such that
3280 # replacement traversals won't ever dig into it.
3281 # its internal structure remains fixed
3282 # regardless of context.
3283 dest_selectable = _shallow_annotate(
3284 dest_selectable, {"no_replacement_traverse": True}
3285 )
3286
3287 primaryjoin, secondaryjoin, secondary = (
3288 self.primaryjoin,
3289 self.secondaryjoin,
3290 self.secondary,
3291 )
3292
3293 # adjust the join condition for single table inheritance,
3294 # in the case that the join is to a subclass
3295 # this is analogous to the
3296 # "_adjust_for_single_table_inheritance()" method in Query.
3297
3298 if single_crit is not None:
3299 if secondaryjoin is not None:
3300 secondaryjoin = secondaryjoin & single_crit
3301 else:
3302 primaryjoin = primaryjoin & single_crit
3303
3304 if extra_criteria:
3305
3306 def mark_exclude_cols(
3307 elem: SupportsAnnotations, annotations: _AnnotationDict
3308 ) -> SupportsAnnotations:
3309 """note unrelated columns in the "extra criteria" as either
3310 should be adapted or not adapted, even though they are not
3311 part of our "local" or "remote" side.
3312
3313 see #9779 for this case, as well as #11010 for a follow up

Calls 7

traverseMethod · 0.95
_shallow_annotateFunction · 0.85
_deep_annotateFunction · 0.85
ClauseAdapterClass · 0.85
and_Method · 0.45
_anonymous_fromclauseMethod · 0.45
chainMethod · 0.45