title: Why are the foreign keys in a SQLAlchemy Association Object marked as primary keys?
body: <p>Below is the documentation from <a href="http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html#association-object" rel="nofollow noreferrer">sqlalchemy</a>.</p>
  
  <p>Notice how for left_id and right_id in the Association Class, they are 
  first marked as ForeignKey and then primary_key = True</p>
  
  <p>It makes sense to me that they should be foreign keys because logically they are foreign keys to the other two parent and child tables.</p>
  
  <p>So whats the purpose of having them be primary keys as well?</p>
  
  <p>Whats going on here? Please explain.</p>
  
  <pre><code>class Association(Base):
      __tablename__ = 'association'
      left_id = Column(Integer, ForeignKey('left.id'), primary_key=True)
      right_id = Column(Integer, ForeignKey('right.id'), primary_key=True)
      extra_data = Column(String(50))
      child = relationship("Child", back_populates="parents")
      parent = relationship("Parent", back_populates="children")
  
  class Parent(Base):
      __tablename__ = 'left'
      id = Column(Integer, primary_key=True)
      children = relationship("Association", back_populates="parent")
  
  class Child(Base):
      __tablename__ = 'right'
      id = Column(Integer, primary_key=True)
      parents = relationship("Association", back_populates="child")
  </code></pre>