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)
>> <mailto:
sqlalchemy+...@googlegroups.com>.
> --
> 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+...@googlegroups.com
> <mailto:
sqlalchemy+...@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