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

Method __init__

lib/sqlalchemy/orm/writeonly.py:500–531  ·  view source on GitHub ↗
(self, attr: WriteOnlyAttributeImpl, state: InstanceState[_T])

Source from the content-addressed store, hash-verified

498 _from_obj: Tuple[FromClause, ...]
499
500 def __init__(self, attr: WriteOnlyAttributeImpl, state: InstanceState[_T]):
501 instance = state.obj()
502 if TYPE_CHECKING:
503 assert instance
504 self.instance = instance
505 self.attr = attr
506
507 mapper = object_mapper(instance)
508 prop = mapper._props[self.attr.key]
509
510 if prop.secondary is not None:
511 # this is a hack right now. The Query only knows how to
512 # make subsequent joins() without a given left-hand side
513 # from self._from_obj[0]. We need to ensure prop.secondary
514 # is in the FROM. So we purposely put the mapper selectable
515 # in _from_obj[0] to ensure a user-defined join() later on
516 # doesn't fail, and secondary is then in _from_obj[1].
517
518 # note also, we are using the official ORM-annotated selectable
519 # from __clause_element__(), see #7868
520 self._from_obj = (prop.mapper.__clause_element__(), prop.secondary)
521 else:
522 self._from_obj = ()
523
524 self._where_criteria = (
525 prop._with_parent(instance, alias_secondary=False),
526 )
527
528 if self.attr.order_by:
529 self._order_by_clauses = self.attr.order_by
530 else:
531 self._order_by_clauses = ()
532
533 def _add_all_impl(self, iterator: Iterable[_T]) -> None:
534 for item in iterator:

Callers

nothing calls this directly

Calls 3

object_mapperFunction · 0.85
_with_parentMethod · 0.80
__clause_element__Method · 0.45

Tested by

no test coverage detected