I'm having some trouble developing my model, and was hoping someone on
this list could help...
Here's what I want:
A BizEntity object
A Person and Company object (both descended from BizEntity, using
joined table inheritance)
A Company.employees attribute, which points to a list of Persons who
work for the company
A Person.company attribute, which points back to the company that
person works for
Whenever I try to combine inheritance with this sort of pseudo-
adjacency-list, I get really odd things happening when I try to query
from the tables...like getting the wrong company back when I query by
id.
Any ideas out there? Anyone done something like this?
MODEL (so far):
(NOTE: the commented out lines are left over from some of my previous
attempts to get things working.)
class BizEntity(Base):
__tablename__ = 'biz_entities'
id = Column('bizentity_id', Integer, primary_key=True)
type = Column('bizentity_type', String(30), nullable=False)
__mapper_args__ = {'polymorphic_on': type}
class Company(BizEntity):
__tablename__ = 'companies'
id = Column(Integer, ForeignKey('biz_entities.bizentity_id'),
primary_key=True)
name = Column('company_name', String(50))
#~ employees = relation("Person", backref=backref("company",
remote_side=[])
#~ backref('parent', remote_side=[nodes.c.id])
__mapper_args__ = {'polymorphic_identity': 'company'}
class Person(BizEntity):
__tablename__ = 'people'
id = Column('bizentity_id', Integer, ForeignKey
('biz_entities.bizentity_id'), primary_key=True)
first_name = Column('first_name', String(50))
middle_init = Column('middle_init', String(1))
last_name = Column('last_name', String(50))
#~ company = relation(Company, backref=backref('employees',
order_by=id))
__mapper_args__ = {'polymorphic_identity':'person'}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---