Here is the code, note in all cases node_id are foreign key/primary_key to a primary_key down the chain:
class Base: """Base Class for SQLAlchemy ORM Classes""" @declared_attr def __tablename__(cls): """Default the Table Name to the Class Name""" return cls.__name__ Base = declarative_base(cls=Base) class Node(Base): """Class repesents the base of the User Data types.""" node_id = Column(Integer, primary_key=True) type_name = Column(String(255), nullable=False) # todo should come from type_id @declared_attr def __mapper_args__(cls): if cls.__name__ == 'Node' : __mapper_args__ = { 'polymorphic_identity': 'Node', 'polymorphic_on': cls.type_name, } else: __mapper_args__ = { 'polymorphic_identity': cls.__tablename__, "inherit_condition": cls.node_id == Node.node_id } return __mapper_args__ class Property(Node): node_id = Column(Integer, ForeignKey('Node.node_id'), primary_key=True) ref_id = Column(Integer, ForeignKey('Node.node_id')) class Name(Property): node_id = Column(Integer, ForeignKey('Property.node_id'), primary_key=True) On 9/2/20 9:39 PM, Mike Bayer wrote: > there's an FAQ entry, a little bit dated but the general idea is still > there, at: > > https://docs.sqlalchemy.org/en/13/faq/ormconfiguration.html#i-m-getting-a-warning-or-error-about-implicitly-combining-column-x-under-attribute-y > > for joined table inheritance, where Name(Node) -> node_id are FK -> > PK, the warning isn't emitted. so please share the mapping if it is > doing this when it shouldnt. > > > On Wed, Sep 2, 2020, at 9:08 PM, Richard Damon wrote: >> I am getting the following error: >> >> SAWarning: Implicitly combining column Node.node_id with column >> Name.node_id under attribute 'node_id'. Please configure one or more >> attributes for these same-named columns explicitly. >> >> In my case I am using poymorphic classes by joining with the ORM. Node >> is the base of the hierarchy (derived from declarative_base), then I >> have a class Property derived from it, and a class Name derived from >> Property. Each class has a primary_key named node_id, with a foreign key >> constraint one step done the hierarchy. I have also tried making all the >> Foreign key constraints point to Node.node_id and it doesn't make a >> difference. >> >> It is just a warning, and the lookup does seem to make the double join, >> so it doesn't seem to be a big problem, but it seems it want me to >> configure something for these, but I am not sure what. >> >> Two level inheritance is working just fine, it is just where it hits the >> 3rd level that it seems to want something explicit. >> >> -- >> Richard Damon >> >> -- >> 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 >> <mailto:sqlalchemy+unsubscr...@googlegroups.com>. >> To view this discussion on the web >> visit >> https://groups.google.com/d/msgid/sqlalchemy/8fa8e94d-cc6f-5bf5-efeb-dbdbae0d7663%40Damon-Family.org. >> > > -- > 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 > <mailto:sqlalchemy+unsubscr...@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/e07cc259-2216-4ece-baf9-daabebf4ac00%40www.fastmail.com > <https://groups.google.com/d/msgid/sqlalchemy/e07cc259-2216-4ece-baf9-daabebf4ac00%40www.fastmail.com?utm_medium=email&utm_source=footer>. -- Richard Damon -- 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/7a9c5943-ff71-2a3e-a139-5feb522070e5%40Damon-Family.org.