Skip to content

Commit d566aa8

Browse files
updated to use ForeignKey
1 parent a729be1 commit d566aa8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

docs/user-guide/development.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Create a new file in `src/app/models/` (e.g., `category.py`):
1414

1515
```python
1616
from sqlalchemy import String, ForeignKey
17-
from sqlalchemy.orm import Mapped, mapped_column, relationship
17+
from sqlalchemy.orm import Mapped, mapped_column
1818

1919
from ..core.db.database import Base
2020

@@ -33,8 +33,8 @@ class Category(Base):
3333
name: Mapped[str] = mapped_column(String(50))
3434
description: Mapped[str | None] = mapped_column(String(255), default=None)
3535

36-
# Relationships
37-
posts: Mapped[list["Post"]] = relationship(back_populates="category")
36+
# No relationships: use ForeignKey only
37+
# Related data is fetched explicitly via CRUD operations
3838
```
3939

4040
#### 2. Create Pydantic Schemas
@@ -667,7 +667,7 @@ uv run alembic upgrade head
667667

668668
```python
669669
# 1. Create the model file (e.g., src/app/models/category.py)
670-
from sqlalchemy import String
670+
from sqlalchemy import String, ForeignKey
671671
from sqlalchemy.orm import Mapped, mapped_column
672672

673673
from app.core.db.database import Base
@@ -678,6 +678,8 @@ class Category(Base):
678678
id: Mapped[int] = mapped_column(primary_key=True)
679679
name: Mapped[str] = mapped_column(String(50))
680680
description: Mapped[str] = mapped_column(String(255), nullable=True)
681+
# Foreign key without relationship
682+
created_by_user_id: Mapped[int] = mapped_column(ForeignKey("user.id"), index=True)
681683
```
682684

683685
```python

0 commit comments

Comments
 (0)