diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-09-30 18:43:54 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-09-30 18:43:54 +0000 |
| commit | 466a09364888eeccea7f5c4e1e5f506211a5cfeb (patch) | |
| tree | 6b003f709d101374f9a7c493d2dfbcb7037459e1 /doc/build/tutorial/metadata.rst | |
| parent | abcd088551fda5490ad56c401a8e8260fae0dcfd (diff) | |
| parent | 23dbf572cec3802d9d54d2f5a52eeaeb18d1c26f (diff) | |
| download | sqlalchemy-466a09364888eeccea7f5c4e1e5f506211a5cfeb.tar.gz | |
Merge "Format code in the rst docs file" into main
Diffstat (limited to 'doc/build/tutorial/metadata.rst')
| -rw-r--r-- | doc/build/tutorial/metadata.rst | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/doc/build/tutorial/metadata.rst b/doc/build/tutorial/metadata.rst index 690626735..1b5699411 100644 --- a/doc/build/tutorial/metadata.rst +++ b/doc/build/tutorial/metadata.rst @@ -76,9 +76,9 @@ that will be how we will refer to the table in application code:: >>> user_table = Table( ... "user_account", ... metadata_obj, - ... Column('id', Integer, primary_key=True), - ... Column('name', String(30)), - ... Column('fullname', String) + ... Column("id", Integer, primary_key=True), + ... Column("name", String(30)), + ... Column("fullname", String), ... ) We can observe that the above :class:`_schema.Table` construct looks a lot like @@ -151,9 +151,9 @@ table:: >>> address_table = Table( ... "address", ... metadata_obj, - ... Column('id', Integer, primary_key=True), - ... Column('user_id', ForeignKey('user_account.id'), nullable=False), - ... Column('email_address', String, nullable=False) + ... Column("id", Integer, primary_key=True), + ... Column("user_id", ForeignKey("user_account.id"), nullable=False), + ... Column("email_address", String, nullable=False), ... ) The table above also features a third kind of constraint, which in SQL is the @@ -331,26 +331,26 @@ types:: >>> from sqlalchemy.orm import relationship >>> class User(Base): - ... __tablename__ = 'user_account' - ... + ... __tablename__ = "user_account" + ... ... id: Mapped[int] = mapped_column(primary_key=True) ... name: Mapped[str] = mapped_column(String(30)) ... fullname: Mapped[Optional[str]] - ... + ... ... addresses: Mapped[List["Address"]] = relationship(back_populates="user") - ... + ... ... def __repr__(self) -> str: - ... return f"User(id={self.id!r}, name={self.name!r}, fullname={self.fullname!r})" + ... return f"User(id={self.id!r}, name={self.name!r}, fullname={self.fullname!r})" >>> class Address(Base): - ... __tablename__ = 'address' - ... + ... __tablename__ = "address" + ... ... id: Mapped[int] = mapped_column(primary_key=True) ... email_address: Mapped[str] - ... user_id = mapped_column(ForeignKey('user_account.id')) - ... + ... user_id = mapped_column(ForeignKey("user_account.id")) + ... ... user: Mapped[User] = relationship(back_populates="addresses") - ... + ... ... def __repr__(self) -> str: ... return f"Address(id={self.id!r}, email_address={self.email_address!r})" @@ -472,7 +472,6 @@ the collection from the ``Base.metadata`` attribute and then using Base.metadata.create_all(engine) - Combining Core Table Declarations with ORM Declarative ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -497,6 +496,7 @@ and should not be run):: class Base(DeclarativeBase): pass + class User(Base): __table__ = user_table @@ -505,6 +505,7 @@ and should not be run):: def __repr__(self): return f"User({self.name!r}, {self.fullname!r})" + class Address(Base): __table__ = address_table |
