BESSER icon indicating copy to clipboard operation
BESSER copied to clipboard

SQLAlchemy generator does not handle unidirectional associations

Open gwendal-jouneaux opened this issue 11 months ago • 2 comments

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 avatar Feb 06 '25 10:02 gwendal-jouneaux

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?

jcabot avatar Feb 06 '25 10:02 jcabot

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

ivan-alfonso avatar Feb 14 '25 17:02 ivan-alfonso

Closing it down as I think our current implementation may not be perfect but still acceptable given that we are targeting SQL. Navigability could be enforced more at the UI level.

jcabot avatar May 27 '25 07:05 jcabot