Skip to content

Support sqlmodel_rebuild #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

adsharma
Copy link

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().

adsharma and others added 2 commits February 27, 2025 10:57
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()`.
@adsharma
Copy link
Author

This was a test to see #1270 had merge errors. Looks like these are real test failures. Looking into them.

@adsharma adsharma closed this Feb 27, 2025
@adsharma adsharma deleted the sqlmodel_rebuild2 branch February 27, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant