title: How can I define a relationship so that it can only have exactly two entries in SQLAlchemy?
body: <p>I have two tables DOOR and ROOM (s. below) where each door should be associated with exactly two rooms and each room can be associated with one or more doors.
  How can i define this constraint with SQLAlchemy?</p>
  <pre><code>door_room_association = Table('association:door-room',
                                DeclarativeBase.metadata,
                                Column('door_id', ForeignKey('door.id'), primary_key=true),
                                Column('room_id', ForeignKey('room.id'), primary_key=true))
  
  class Door(DeclarativeBase):
      id: Column(String, primary_key=true)
      locked: Column(Boolean)
      rooms = relationship('Room', secondary=door_room_association, back_populates=&quot;doors&quot;)
  
  class Room(DeclarativeBase):
      id: Column(String, primary_key=true)
      name: Column(String)
      doors = relationship('Door', secondary=door_room_associaiton, back_populates=&quot;rooms&quot;)
  </code></pre>