MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _ORMColumnEntity

Class _ORMColumnEntity

lib/sqlalchemy/orm/context.py:3316–3462  ·  view source on GitHub ↗

Column/expression based entity.

Source from the content-addressed store, hash-verified

3314
3315
3316class _ORMColumnEntity(_ColumnEntity):
3317 """Column/expression based entity."""
3318
3319 supports_single_entity = False
3320
3321 __slots__ = (
3322 "expr",
3323 "mapper",
3324 "column",
3325 "_label_name",
3326 "entity_zero_or_selectable",
3327 "entity_zero",
3328 "_extra_entities",
3329 )
3330
3331 def __init__(
3332 self,
3333 compile_state,
3334 column,
3335 entities_collection,
3336 parententity,
3337 raw_column_index,
3338 is_current_entities,
3339 parent_bundle=None,
3340 ):
3341 annotations = column._annotations
3342
3343 _entity = parententity
3344
3345 # an AliasedClass won't have proxy_key in the annotations for
3346 # a column if it was acquired using the class' adapter directly,
3347 # such as using AliasedInsp._adapt_element(). this occurs
3348 # within internal loaders.
3349
3350 orm_key = annotations.get("proxy_key", None)
3351 proxy_owner = annotations.get("proxy_owner", _entity)
3352 if orm_key:
3353 self.expr = getattr(proxy_owner.entity, orm_key)
3354 self.translate_raw_column = False
3355 else:
3356 # if orm_key is not present, that means this is an ad-hoc
3357 # SQL ColumnElement, like a CASE() or other expression.
3358 # include this column position from the invoked statement
3359 # in the ORM-level ResultSetMetaData on each execute, so that
3360 # it can be targeted by identity after caching
3361 self.expr = column
3362 self.translate_raw_column = raw_column_index is not None
3363
3364 self.raw_column_index = raw_column_index
3365
3366 if is_current_entities:
3367 if parent_bundle:
3368 self._label_name = orm_key if orm_key else column._proxy_key
3369 else:
3370 self._label_name = compile_state._label_convention(
3371 column, col_name=orm_key
3372 )
3373 else:

Callers 1

_for_columnsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected