On Wed, Sep 23, 2009 at 12:27 AM, Michael Bayer <mike...@zzzcomputing.com>wrote:

>
>
> On Sep 22, 2009, at 11:59 AM, Kevin H wrote:
>
> >
> > 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?
>
> I'm doing this.


Howdy, Michael!  Knowing that I'm not trying to do something impossible is
definitely a relief.


> The first thing to do is to definitely be on 0.5.6
> at the least.
>

OK, I'm on 0.5.5, so that's the first thing to fix, I guess.


> the next thing is to define the employees/company thing only once, as
> a relation/backref pair on just one of your mapped classes.   doing it
> twice will mess things up for sure.
>
>
Good to know, thanks.


> your example also mentions a table called "nodes" which from
> everything else mentioned below would be erroneous.   you don't need
> remote_side when mapping between Company and Person.
>

Wow, that's from something _really_ old.  Been commented out for a while...I
didn't even notice that.


> None of this would cause the wrong "Company" to come back from a
> simple query by id, though.   If that is really the effect you're
> seeing then something more fundamental might be amiss.
>

Looking at it again, it looks like this was caused by a problem in my
tests.  I was assuming something I shouldn't have been about the order of
the data I was testing.

Thanks for the pointers, I'll post back later with results.

Kevin Horn


>
> >
> > 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 sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to