I am confused when I want to define the relation of User and User's Friends (a user is another user's friend)
There is a example about association object pattern at http://www.sqlalchemy.org/docs/05/mappers.html#association-object Code from the document: left_table = Table('left', metadata, Column('id', Integer, primary_key=True)) right_table = Table('right', metadata, Column('id', Integer, primary_key=True)) association_table = Table('association', metadata, Column('left_id', Integer, ForeignKey('left.id'), primary_key=True), Column('right_id', Integer, ForeignKey('right.id'), primary_key=True), Column('data', String(50)) ) mapper(Parent, left_table, properties={ 'children':relation(Association)}) mapper(Association, association_table, properties={ 'child':relation(Child)}) mapper(Child, right_table) -------------------------------------------------------------------------------------------------- The left table and right table are different tables in this example, so how can we do the mapper configuration if the right table is the same as left table? For example(User and User's friends): user_table = Table("user", meta.metadata, Column("id", types.Integer, primary_key=True), Column("username", types.String(30), unique=True, nullable=False), Column("email", types.String(128), unique=True, nullable=False), ) friend_table = Table('friend', meta.metadata, Column('user_id', types.Integer, ForeignKey('user.id'), primary_key=True), Column('friend_id', types.Integer, ForeignKey('user.id'), primary_key=True), Column("notes", types.String(80), nullable=True), ) class User(object): pass class Friend(object): pass -------------------------------------------------------------------------------------------------- when i try to do the mapper like below: orm.mapper(User, user_table, properties={ 'friends': orm.relation(Friend), }) orm.mapper(Friend, friend_table, properties={ 'user': orm.relation(User) }) I got those error messages ArgumentError: Could not determine join condition between parent/child tables on relation Friend.user. Specify a 'primaryjoin' expression. If this is a many-to-many relation, 'secondaryjoin' is needed as well. So, how can we handle this? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---