📝 Add docs page for self-referential model#408
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@tiangolo, what's blocking this from being merged? |
|
This is some really helpful documentation. @svlandeg anything we can do to get this merged? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
YuriiMotov
left a comment
There was a problem hiding this comment.
@daniil-berg, thanks for working on this!
Great job!
I suggested a few minor improvements. Could you please take a look?
Also, we should probably create a group in Advanced (e.g. "Advanced Relationships") for other relationships-related sections such as #815
This comment was marked as outdated.
This comment was marked as outdated.
Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
This comment was marked as outdated.
This comment was marked as outdated.
📝 Docs previewLast commit 53809d1 at: https://fef55e49.sqlmodel.pages.dev Modified Pages |
svlandeg
left a comment
There was a problem hiding this comment.
I didn't review in detail (as Yurii already did 🙌), but just a few small nitpicks 😇
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
|
So currently what is the link of this self-reference docs link? |
Today i read this docs, thinking the Villain example i made like this, i found and understand your explanations, i give you thanks for this easy explanation. See i wanted to make a billing system where i need to keep record of product and its category, and i found category can have its own category like this, so after the Villain example you give in your article here i found i did something like this,
I am not properly sure is this a right way to use like this?
or any problem it can happens here?
Can you please check the `parent_id` & `parent_obj` field in the Sqlmodel class i made for category
|

Purpose
Adds a new page explaining how to construct a self-referential/recursive relationship with SQLModel to the Advanced User Guide section of the documentation. This is arguably a fairly common use case that has been asked about and discussed in issue #127 already.
Code
The example code uses a
Villainclass/model for demonstration in an attempt at honoring theHerotheme of the documentation. A villain can have abossvillain and villainminions.Additional info
The new page also includes a brief explanation of the
sa_relationship_kwargsparameter of theRelationshipconstructor, since that is essential for defining the desired relationship. Depending on how @tiangolo wants to structure the rest of the advanced guide, this section may either need to be expanded or instead abbreviated to a short mention and link to a dedicated section forsa_-style parameters in SQLModel fields and relationships in the future.Update (2022-08-02)
Rebased onto most recent version of the
mainbranch (0.0.8 release, 75ce455).Then rebased again, after adding tests to cover the new documentation example code. Coverage of the added code should now be at 100% (see latest codecov checks).