Skip to content

Instantly share code, notes, and snippets.

@rclark72
Last active December 26, 2015 18:59
Show Gist options
  • Save rclark72/7198432 to your computer and use it in GitHub Desktop.
Save rclark72/7198432 to your computer and use it in GitHub Desktop.
# What I have
following = db.relationship('User',
secondary=UserFollowing.__table__,
primaryjoin='User.id==UserFollowing.user1_id',
secondaryjoin='User.id==UserFollowing.user2_id',
foreign_keys=[UserFollowing.user1_id, UserFollowing.user2_id],
lazy='joined')
# What I want
following = db.relationship('User',
secondary=UserFollowing.__table__,
primaryjoin='and_(User.id==UserFollowing.user1_id, remote(User.id==UserFollowing.user1_id))',
foreign_keys='[UserFollowing.user1_id]',
lazy='joined')
# Error:
# InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: Relationship User.following could not determine any unambiguous local/remote column pairs based on join condition and remote_side arguments. Consider using the remote() annotation to accurately mark those elements of the join condition that are on the remote side of the relationship.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment