On Aug 12, 2010, at 6:54 PM, Nikolaj wrote:
> Hi there,
>
> I'm exploring the bidirectional adjacency list pattern described in
> the documentation (the scalar relationship is intentional):
>
> Person.child = relationship(
> Person,
> uselist=False,
> backref=backref('parent', remote_side=Person.id)
> )
>
> However, I'd like to add an additional primaryjoin condition,
> something to the effect of:
>
> child = aliased(Person)
>
> Person.child_bob = relationship(
> child,
> uselist=False,
> primaryjoin=and_(
> child.parent_id == Person.id,
> child.name == 'Bob'
> ),
> backref=backref('parent', remote_side=Person.id)
> )
>
> But of course I can't use an AliasedClass in the first argument to
> relationship(). Similarly I can't add the relationship property onto
> an aliased parent class. What's the proper way of defining such a
> relationship?
You don't need aliased() in relationship, since the load is either lazy, in
which case its against only one side at a time, or eager, in which case
aliasing is applied to the "remote side" columns. So here the join condition
is just and_(parent_id==id, name=='Bob') and remote_side is [parent_id, name].
I haven't tried it though and its a little intricate so I could be wrong.
--
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.