I tried to look for quite a while and didn't find a solution to my specific problem, so I apologize in advance.
Suppose I have the following model with tables Users and Follows:
________ src ________
| User |-1------------*-| Follow |
|--------| |--------|
| id | | src_id |
| | | dst_id |
| | | string |
|________|-1------------*-|________|
dst
Notice that that there are different semantics depending on the foreign keys.
I'm trying to achieve this through the "association pattern" (described here), but I can get it to work. It looks something like this:
class Follow(Base):
__tablename__ = 'follows'
#
src_id = Column(BigInteger, ForeignKey('users.id'), primary_key=True)
dst_id = Column(BigInteger, ForeignKey('users.id'), primary_key=True)
src = relationship("User", back_populates="followers", foreign_keys=[src_id])
dst = relationship("User", back_populates="followees", foreign_keys=[dst_id])
kind = Column(String(16))
class User(Base):
__tablename__ = 'users'
name = Column(String(20))
followers = relationship("UUEdge", primaryjoin="User.id==UUEdge.dst_id")
followees = relationship("UUEdge", primaryjoin="User.id==UUEdge.src_id")
Is this possible? Am I doing something wrong?
Cheers
P.S.
Similar question that does not answer mine: