> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> On Behalf Of Joril
> Sent: 08 June 2011 22:41
> To: sqlalchemy
> Subject: [sqlalchemy] Filtered backref
>
> Hi everyone!
> Is it possible to have a many-to-one declarative relation between two
> classes and a _filtered_ backref?
>
> I'm trying to build a tagging system for my bloglike application, and
> to allow a user to apply private tags to posts of other people. My
> classes are:
> Owner
> Post
> TagAssociation
> Tag
>
> A Post has an Owner, while TagAssociation has a Tag, a Post and an
> Onwer
>
> Between TagAssociation and Post there's a many-to-one, and I'd like
> to
> configure a "tags" backref so that it would handle only the
> TagAssociations having the same Owner as the Post... Is this possible?
>
> Many thanks!
>
The 'relationship' function takes optional primaryjoin and secondaryjoin
parameters that control the join conditions for the relationship. So I
think you should be able to do something like this:
import sqlalchemy as sa
class TagAssociation(Base):
# columns including "owner_id" and "post_id"
class Post(Base):
# columns including "id" and "owner_id"
tags = relationship(
TagAssociation,
primary_join=(sa.and_(id == TagAssociation.post_id,
owner_id == TagAssociation.owner_id)))
I think you would have to treat this relationship as readonly, so you
might need/want to add viewonly=True.
Hope that helps,
Simon
--
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.