SQLAlchemy relationships on inherited attributes fail
Issue #2723
resolved
In the given example below, I get the following error while mappers are being configured:
if nrte.table_name == b.name:
AttributeError: 'Join' object has no attribute 'name'
This appears to be because the foreign key is a property of the parent model, rather than the target model. Please ignore that this could be avoided by using the id
column as foreign key in the example, as this is not possible in my 'real' case.
class Person(Base):
__tablename__ = 'people'
id = Column(Integer, primary_key=True)
type = Column(Enum('staff', 'student'))
username = Column(String)
__mapper_args__ = {
'polymorphic_on': type
}
class Staff(A):
__tablename__ = 'staff'
id = Column(Integer, ForeignKey(People.id), primary_key=True)
__mapper_args__ = {
'polymorphic_identity': 'staff'
}
class Department(Base):
__tablename__ = 'departments'
id = Column(Integer, primary_key=True)
head_username = Column(String, ForeignKey(Staff.username))
head = relationship(Staff)
This is in SQLAlchemy 0.8.0
Comments (2)
-
repo owner -
repo owner - changed status to wontfix
okey doke, reopen when you have time to post a test case, thanks !
- Log in to comment
can you fix up your test please? I'm not sure what "A" is, or "People", I've created a simple test as below and there's no issue: