SQLalchemy prescribes a pattern for dealing with polymorphic relationships 
which are one to many. You can see this pattern here: 
https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/api.html#sqlalchemy.ext.declarative.AbstractConcreteBase

After implementing this pattern I was pleased to find that it correctly 
created my tables for the child classes, did not create a table for the 
parent class, and successfully loads all children into a single collection 
on the one side of the one to many. Basically everything I wanted.

Unfortunately, I quickly came to discover that all child classes had all 
the fields of all the other child classes.  This doesn't happen on the 
tables, it is only present on the ORM objects after they are loaded. This 
presents an incredibly poor user experience for the developer. When they 
inspect these objects they discover a litany of irrelevant fields. Further, 
tools which visualize the data structure include these fields, making the 
visualization extremely confusing. For more in depth explanation of my 
specific implementation you can refer to the stack overflow post: 
https://stackoverflow.com/questions/60469773/sqlalchemy-polymorphic-pattern-creates-duplicated-columns

Does anyone know how to prevent SQL alchemy from including fields from 
sister objects when implementing this pattern?


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/7a740ba1-ade8-40fc-914e-85c390e370a8%40googlegroups.com.

Reply via email to