Skip to content

Commit 7bdeea6

Browse files
Updating docs/user-guide/development.md to use SQLAlchemy 2.0 syntax.
1 parent 7c58913 commit 7bdeea6

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

docs/user-guide/development.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,34 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
1919
from ..core.db.database import Base
2020

2121

22+
```
2223
class Category(Base):
2324
__tablename__ = "category"
2425

2526
id: Mapped[int] = mapped_column(
26-
"id",
27-
autoincrement=True,
28-
nullable=False,
29-
unique=True,
30-
primary_key=True,
31-
init=False
27+
"id",
28+
autoincrement=True,
29+
nullable=False,
30+
unique=True,
31+
primary_key=True,
32+
init=False,
3233
)
34+
3335
name: Mapped[str] = mapped_column(String(50))
3436
description: Mapped[str | None] = mapped_column(String(255), default=None)
35-
36-
# Relationships
37-
posts: Mapped[list["Post"]] = relationship(back_populates="category")
37+
38+
39+
class Post(Base):
40+
__tablename__ = "post"
41+
42+
id: Mapped[int] = mapped_column(primary_key=True)
43+
title: Mapped[str] = mapped_column(String(100))
44+
45+
category_id: Mapped[int | None] = mapped_column(
46+
ForeignKey("category.id"),
47+
index=True,
48+
default=None
49+
)
3850
```
3951
4052
#### 2. Create Pydantic Schemas

0 commit comments

Comments
 (0)