I have the following setup (attached python file). I'm using an inheritance hierarchy without a discriminator field, deriving from AbstractBase. I want to be able to use the "keywords" attribute in the "SuperUser" class, and from the documentation I understand I need to redefine it, however that doesn't seem to work. I assume I could manually use a primary join there (as the error indicates), but as I understand that's exactly what "AbstractBase" class should handle...
-- 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 post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
from sqlalchemy import ForeignKey from sqlalchemy import Integer from sqlalchemy import Column from sqlalchemy import String from sqlalchemy import create_engine from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.declarative import ConcreteBase from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship, backref from sqlalchemy.orm import sessionmaker Base = declarative_base() # Inheritance without discriminator class User(ConcreteBase, Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) keywords = association_proxy('user_keywords', 'keyword') __mapper_args__ = {'polymorphic_identity': 'user', 'concrete': True} class UserKeyword(Base): __tablename__ = 'user_keyword' user_id = Column(Integer, ForeignKey('user.id'), primary_key=True) keyword_id = Column(Integer, ForeignKey('keyword.id'), primary_key=True) special_key = Column(String(50)) user = relationship(User, backref=backref("user_keywords", cascade="all, delete-orphan") ) keyword = relationship("Keyword") def __init__(self, keyword=None, user=None, special_key=None): self.user = user self.keyword = keyword self.special_key = special_key class Keyword(Base): __tablename__ = 'keyword' id = Column(Integer, primary_key=True) keyword = Column('keyword', String(64)) def __init__(self, keyword): self.keyword = keyword def __repr__(self): return 'Keyword(%s)' % repr(self.keyword) class SuperUser(User): __tablename__ = 'super_user' id = Column(Integer, ForeignKey(User.id), primary_key=True) role = Column(String(64)) __mapper_args__ = {'polymorphic_identity': 'super_user', 'concrete': True} # ???? user_keywords = relationship(UserKeyword) keywords = association_proxy('user_keywords', 'keyword') engine = create_engine('sqlite:///:memory:', echo=False) Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() user = SuperUser() for kw in (Keyword('new_from_blammo'), Keyword('its_big')): user.keywords.append(kw) session.add(user) session.commit()