MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / UserStyleTwo

Class UserStyleTwo

test/typing/plain_files/ext/hybrid/hybrid_three.py:60–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58
59
60class UserStyleTwo(Base):
61 __tablename__ = "user"
62 id: Mapped[int] = mapped_column(primary_key=True)
63 name: Mapped[str] = mapped_column(String(100))
64
65 accounts: Mapped[List[SavingsAccount]] = relationship()
66
67 @hybrid_property
68 def balance(self) -> Optional[Decimal]:
69 if self.accounts:
70 return self.accounts[0].balance
71 else:
72 return None
73
74 @balance.inplace.setter
75 def _balance_setter(self, value: Optional[Decimal]) -> None:
76 assert value is not None
77 if not self.accounts:
78 account = SavingsAccount(owner=self)
79 else:
80 account = self.accounts[0]
81 account.balance = value
82
83 @balance.inplace.expression
84 def _balance_expression(cls) -> SQLColumnExpression[Optional[Decimal]]:
85 return cast(
86 "SQLColumnExpression[Optional[Decimal]]", SavingsAccount.balance
87 )

Callers

nothing calls this directly

Calls 3

mapped_columnFunction · 0.90
StringClass · 0.90
relationshipFunction · 0.90

Tested by

no test coverage detected