title: SQLAlchemy multiple foreign keys in one mapped class to the same primary key
body: <p>Am trying to setup a postgresql table that has two foreign keys that point to the same primary key in another table. </p>
  
  <p>When I run the script I get the error </p>
  
  <blockquote>
    <p>sqlalchemy.exc.AmbiguousForeignKeysError: Could not determine join condition between parent/child tables on relationship Company.stakeholder - there are multiple foreign key paths linking the tables.  Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference to the parent table.</p>
  </blockquote>
  
  <p>That is the exact error in the <a href="http://docs.sqlalchemy.org/en/latest/orm/join_conditions.html#handling-multiple-join-paths" rel="noreferrer">SQLAlchemy Documentation</a> yet when I replicate what they have offered as a solution the error doesn't go away. What could I be doing wrong?</p>
  
  <pre><code>#The business case here is that a company can be a stakeholder in another company.
  class Company(Base):
      __tablename__ = 'company'
      id = Column(Integer, primary_key=True)
      name = Column(String(50), nullable=False)
  
  class Stakeholder(Base):
      __tablename__ = 'stakeholder'
      id = Column(Integer, primary_key=True)
      company_id = Column(Integer, ForeignKey('company.id'), nullable=False)
      stakeholder_id = Column(Integer, ForeignKey('company.id'), nullable=False)
      company = relationship("Company", foreign_keys='company_id')
      stakeholder = relationship("Company", foreign_keys='stakeholder_id')
  </code></pre>
  
  <p>I have seen similar questions here but <a href="https://stackoverflow.com/a/9222924/1082673">some of the answers</a> recommend one uses a <code>primaryjoin</code> yet in the documentation it states that you don't need the <code>primaryjoin</code> in this situation.</p>