[Sqlalchemy-tickets] [sqlalchemy] #2723: SQLAlchemy relationships on inherited attributes fail
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-05-07 14:58:51
|
#2723: SQLAlchemy relationships on inherited attributes fail
-------------------------------------+-------------------------------------
Reporter: mitchellrj | Owner: zzzeek
Type: defect | Status: new
Priority: medium | Milestone:
Component: orm | Severity: no triage selected
Keywords: relationship inherited | yet
inheritance foreign key | Progress State: awaiting triage
-------------------------------------+-------------------------------------
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
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2723>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|