|
1 | | -from typing import List, Optional |
2 | | - |
3 | 1 | from sqlmodel import Field, Relationship, String, UniqueConstraint |
4 | 2 |
|
5 | 3 | from common.enums import Grade |
|
8 | 6 |
|
9 | 7 | class Teacher(IdBaseTable, table=True): |
10 | 8 | __table_args__ = (UniqueConstraint("phone", "id", name="phone_id"),) |
| 9 | + |
11 | 10 | phone: float |
12 | | - students: Optional[List["Student"]] = Relationship( |
13 | | - sa_relationship_kwargs={"cascade": "all, delete"}, back_populates="teacher" |
| 11 | + |
| 12 | + students: list["Student"] | None = Relationship( |
| 13 | + sa_relationship_kwargs={"cascade": "all, delete"}, |
| 14 | + back_populates="teacher", |
14 | 15 | ) |
15 | 16 |
|
16 | | - assignments: Optional[List["Assignment"]] = Relationship( |
17 | | - sa_relationship_kwargs={"cascade": "all, delete"}, back_populates="teacher" |
| 17 | + assignments: list["Assignment"] | None = Relationship( |
| 18 | + sa_relationship_kwargs={"cascade": "all, delete"}, |
| 19 | + back_populates="teacher", |
18 | 20 | ) |
19 | 21 |
|
20 | 22 |
|
21 | 23 | class Student(IdBaseTable, table=True): |
22 | 24 | __table_args__ = (UniqueConstraint("name", "phone", name="name_phone"),) |
| 25 | + |
23 | 26 | teacher_id: int = Field(foreign_key="teacher.id") |
24 | 27 | teacher: Teacher = Relationship(back_populates="students") |
25 | 28 |
|
26 | 29 | name: str |
27 | 30 | grade: Grade = Field(sa_type=String, nullable=False) |
28 | 31 |
|
29 | 32 | phone: float |
30 | | - assignments: Optional[List["Assignment"]] = Relationship( |
31 | | - sa_relationship_kwargs={"cascade": "all, delete"}, back_populates="student" |
| 33 | + |
| 34 | + assignments: list["Assignment"] | None = Relationship( |
| 35 | + sa_relationship_kwargs={"cascade": "all, delete"}, |
| 36 | + back_populates="student", |
32 | 37 | ) |
33 | 38 |
|
34 | 39 |
|
|
0 commit comments