| 58 | |
| 59 | |
| 60 | class 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 | ) |
nothing calls this directly
no test coverage detected