Hello Az,
    Yes, Bar is the association table of Foo to Foo. In essence, this is a
self join through a join table.. I have tried and hit my head on this for
(quite literally) hours. In the end, and for the record, I ended up creating
a method on the model itself such as ;

    def children(self):
        childFoo=Foo.__table__.alias()
        return
object_session(self).query(Foo).filter(and_(childFoo.c.deleted == 0,
childFoo.id <> self.id, self.id == Bar.parent_id))

    Not the prettiest way, nor what I would expect, but in lieu of an actual
example, and to help anyone who ends up treading the same path as me, I hope
this helps.

    Regards
    Stef

On Wed, Feb 25, 2009 at 4:29 AM, <a...@svilendobrev.com> wrote:

>
> u mean, the Bar is an association table of Foo to Foo?
> u have to use secondary_table and/or secondary_join in the relation
> setup. And probably specify remote_side or it may not know which Foo
> is what.
>
> On Wednesday 25 February 2009 03:39:20 Stef wrote:
> > Hello Everyone,
> >    First of all, kudos on SQLAlchemy.. the speed is pretty amazing
> > - I am coming from the SQLObject world and there is a definite
> > difference. Excellent work. I am also getting to grips with it
> > pretty quickly, using object_session and all that good stuff. This
> > said, I have hit that 20% problem, and am hoping someone can shine
> > a light on it.
> >
> >    I have a table, lets call it Foo and another table Bar. Foo
> > should be able to get a list of it's parents via Bar or it's
> > children via Bar. I am also using the declarative_base system
> > rather than table/ mapper defined seperately.
> >
> >    class Foo(Base):
> >         id = Column(Integer, primary_key=True)
> >
> >    class Bar(Base):
> >         parent_id = Column(Integer, default=0)
> >         child_id = Column(Integer, default=0)
> >
> >    So, I thought something like ; children = relation(Foo,
> > backref=backref('parents'), primaryjoin=and_(Foo.id==Bar.parent_id)
> >
> >    But that's where I hit the 'wall' as it were, is there a way to
> > setup a synonym for Foo in the primaryjoin clause ? Am I missing
> > something stupid ? (I am okay with that ;)
> >
> >    Regards
> >    Stef
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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