Skip to content

Commit 5d1ae40

Browse files
Improve relationship example (#680)
1 parent b9c7335 commit 5d1ae40

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

examples/_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Author(Base):
3939
__tablename__ = "author"
4040

4141
id: Mapped[int] = mapped_column(primary_key=True)
42+
name: Mapped[str]
4243
books: Mapped[list["Book"]] = relationship()
4344

4445

examples/relationships.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ async def create_app() -> web.Application:
2323
async with engine.begin() as conn:
2424
await conn.run_sync(Base.metadata.create_all)
2525
async with session.begin() as sess:
26-
sess.add(Author())
27-
author1 = Author()
26+
sess.add(Author(name="John Doe"))
27+
author1 = Author(name="Jane Smith")
2828
sess.add(author1)
2929
async with session.begin() as sess:
3030
sess.add(Book(author_id=author1.id, title="Book 1"))
@@ -40,7 +40,7 @@ async def create_app() -> web.Application:
4040
"secure": False
4141
},
4242
"resources": (
43-
{"model": SAResource(engine, Author)},
43+
{"model": SAResource(engine, Author), "repr": "name"},
4444
{"model": SAResource(engine, Book)}
4545
)
4646
}

0 commit comments

Comments
 (0)