I'm considering modeling many-to-many "friend" relationships between
users using an association table.  The tricky aspect is that I'd like
the association table's entries to be "bidirectional", meaning the
single entry (A,B) represents friendship in both directions.

The "standard" way to model this doesn't support that usage:

friendship_table = Table('friendship',
    Column('user_id', Integer, ForeignKey('user.id')),
    Column('friend_id', Integer, ForeignKey('user.id'))
)

class User(Base):
    id = Column(db.Integer, primary_key=True)
    friends = db.relationship('User',
                              secondary=friendship_table,
                              primaryjoin=id==friendship_table.c.user_id,
                              secondaryjoin=id==friendship_table.c.friend_id)

... and I understand why it can't work as-is.  My question is whether
or not this type of relationship is possible to represent using
relationship() (perhaps by using association_proxy()?).

For the time being, I've just been writing per-operation queries in
User instance methods and @property descriptors, but it would be nice
to wrap this up in an proper attributed object that plays nicely with
the session.

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