sqlmodel
sqlmodel copied to clipboard
Add one-to-one relationship tutorial to docs
First Check
- [X] I added a very descriptive title to this issue.
- [X] I used the GitHub search to find a similar issue and didn't find it.
- [X] I searched the SQLModel documentation, with the integrated search.
- [X] I already searched in Google "How to X in SQLModel" and didn't find any information.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to SQLModel but to Pydantic.
- [X] I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- [X] I commit to help with one of those options 👆
Example Code
n.a.
Description
It would be great to have an "how to" about one-to-one relationships directly in the official docs. An adaption of the sqlalchemy docs example about one-to-on relationships (https://docs.sqlalchemy.org/en/14/orm/basic_relationships.html#one-to-one) should do the job.
Operating System
Linux
Operating System Details
No response
SQLModel Version
n.a.
Python Version
n.a.
Additional Context
No response
you just need to make a simple relation like here: https://sqlmodel.tiangolo.com/tutorial/relationship-attributes/
Not really. Since there's no option uselist=False
for the relationship, you always get a list (so it's one-to-many) even if not possible (if you make the FK the PK).
"workaround" for future readers: https://github.com/tiangolo/sqlmodel/issues/132