Skip to content
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

SQLAlchemy generator does not handle unidirectional associations #210

Open
gwendal-jouneaux opened this issue Feb 6, 2025 · 2 comments
Open
Labels
bug Something isn't working

Comments

@gwendal-jouneaux
Copy link

Describe the bug

The SQLAlchemy generator transform unidirectional associations to bidirectional associations

To Reproduce

  1. Create any model with a unidirectional association
  2. Generate SQLAlchemy code
  3. The generated code transformed the unidirectional relation to a bidirectional one

Expected behavior

No back population nor inverse relation created for this association

Screenshots

Image

Image

@gwendal-jouneaux gwendal-jouneaux added the bug Something isn't working label Feb 6, 2025
@jcabot
Copy link
Collaborator

jcabot commented Feb 6, 2025

Well, in "pure" SQL, navigability is not a factor and foreign keys are added to the class where it makes sense based on the cardinality. Should this be really different in SQLAlchemy?

@ivan-alfonso
Copy link
Collaborator

We could update the generator to remove the relationship (last line in the code above) when the navigability is False. This would keep the Foreign Key in the Pet table, ensuring it’s still associated with a Person, but Pet wouldn’t be able to directly access Person. This is possible in SQLAlchemy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants