When using concrete table inheritance in the complete example below:
1. why must I return an empty `Column(Integer)` instead of `None`, or
receive the following error: *"ArgumentError: Mapper
Mapper|ARefClass|arefclass could not assemble any primary key columns for
mapped table 'arefclass'"*
2. why must I reference the class by name and not type in
`@declarad_attr`, unlike in a `classmethod`?
3. how does the `__tablename__` `declaredattr` actually behave any
differently than the `id` `declaradattr`?
from sqlalchemy import (
Column,
ForeignKey,
Integer,
create_engine,
)
from sqlalchemy.ext.declarative import (
AbstractConcreteBase,
declared_attr,
declarative_base,
has_inherited_table,
)
from sqlalchemy.orm import Session
Base = declarative_base()
class AClass(Base):
__tablename__ = 'aclass'
id = Column(Integer, primary_key=True)
class BClass(Base):
__tablename__ = 'bclass'
id = Column(Integer, primary_key=True)
class RefClass(AbstractConcreteBase, Base):
@declared_attr
def __tablename__(cls):
return cls.__name__.lower()
@declared_attr.cascading
def id(cls):
if cls.__name__ != 'RefClass':
column_name = '{}.id'.format(cls.ref.__tablename__)
return Column(ForeignKey(column_name), primary_key=True)
else:
# return # Fails as described in Q1
return Column(Integer)
class ARefClass(RefClass):
ref = AClass
class BRefClass(RefClass):
ref = BClass
engine = create_engine('sqlite://', echo=True)
Base.metadata.bind = engine
Base.metadata.create_all()
db = Session(engine)
Thanks!
Devin
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.