Commit dd3240c
committed
Support
The `@sqlmodel` decorator introduced by `fquery.sqlmodel` moves schema
definitions and types closer to the object model (references) instead of
foreign_keys.
Instead of writing:
```
class Hero(SQLModel, table=True):
...
team_id: int | None = Field(default=None, foreign_key="team.id")
```
you could write:
```
@sqlmodel
class Hero:
...
team: Team | None = foreign_key("team.id")
```
Everything works the same as before. Only the syntax has changed.
However, if `Team` also has a foreign key to `Hero`, then one of them
will have to use forward declaration so type checkers work.
In those cases we need a two pass solution where in the second pass,
with the full type definition available, we can generate the correct
code.
Refactor some of the existing code to introduce `sqlmodel_rebuild()`.sqlmodel_rebuild
1 parent 7d00768 commit dd3240c
1 file changed
+16
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
588 | | - | |
589 | 588 | | |
590 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
591 | 606 | | |
592 | 607 | | |
593 | 608 | | |
| |||
0 commit comments