Skip to content

Support Sqlmodel link models - #486

Open
sheinbergon wants to merge 4 commits into
agronholm:masterfrom
sheinbergon:sqlmodel-link-models
Open

Support Sqlmodel link models#486
sheinbergon wants to merge 4 commits into
agronholm:masterfrom
sheinbergon:sqlmodel-link-models

Conversation

@sheinbergon

@sheinbergon sheinbergon commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Changes

Fixes #405

Association tables with a primary key are now generated as SQLModel link model classes and referenced via Relationship(link_model=...), matching the SQLModel documentation. Link tables without a primary key still render as plain Table. A new nolinktables option restores the previous output.

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) which would fail without your patch
  • You've added a new changelog entry (in CHANGES.rst).

sheinbergon and others added 3 commits September 4, 2026 15:50
Association tables that have a primary key are now generated as
`SQLModel` table classes (without relationships of their own) and
referenced from both sides via `Relationship(link_model=...)` instead of
`sa_relationship_kwargs={'secondary': ...}`, matching the idiom from the
SQLModel documentation. Link tables without a primary key cannot be
SQLModel classes and keep the previous plain `Table` output.

The link model classes are emitted before the classes referencing them,
since `link_model=` needs the class object rather than a string.

Fixes agronholm#405

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Opts out of rendering association tables as link model classes, keeping
the previous plain Table + secondary= output.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coveralls

coveralls commented Sep 4, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 97.849% (+0.05%) from 97.798% — sheinbergon:sqlmodel-link-models into agronholm:master

@agronholm

Copy link
Copy Markdown
Owner

This may take a while to review.

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.

SQLModel does not generate many-to-many classes correctly

3 participants