sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

Add one-to-one relationship tutorial to docs

Open fkromer opened this issue 1 year ago • 3 comments

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

fkromer avatar Jul 20 '22 10:07 fkromer

you just need to make a simple relation like here: https://sqlmodel.tiangolo.com/tutorial/relationship-attributes/

Beafowl-Pull avatar Jul 21 '22 07:07 Beafowl-Pull

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

m0wer avatar Apr 04 '23 06:04 m0wer

"workaround" for future readers: https://github.com/tiangolo/sqlmodel/issues/132

Kyu avatar Apr 12 '24 18:04 Kyu