title: SQLAlchemy delete many to many with Association Object
body: <p>So I have myself a many to many relationship which requires extra data in the association table. As a result, I have used an Association Object.</p>
  <p>I can delete the Association Object itself from the DB just fine, but there doesn't seem to be any cascade taking place. I have looked at the documentation and followed it as best I could (I'm somewhat of a beginner here), but the situation as explained there does not seem to apply to my situation entirely (and I can't quite figure out the way to get it to work right).</p>
  <p>So I have three classes. Student, CMClass and StudentClass (this being the Association Object):</p>
  <pre class="lang-python prettyprint-override"><code>class Student(Base):
      __tablename__ = 'Students'
      
      id = Column('ID', Integer, primary_key=True, autoincrement=True)
      name = Column('NAME', String(50), unique=True)
      CMClasses = relationship(&quot;StudentClass&quot;, back_populates=&quot;Student&quot;, secondary=&quot;StudentClasses&quot;, cascade=&quot;all, delete&quot;)
      
  class CMClass(Base):
      __tablename__ = &quot;Classes&quot;
      
      id = Column('ID', Integer, primary_key=True, autoincrement=True)
      name = Column('NAME', String(50), unique=True)
      classDate = Column('CLASS_DATE', DateTime, nullable=True)
      Students = relationship(&quot;StudentClass&quot;, back_populates=&quot;CMClass&quot;, secondary=&quot;StudentClasses&quot;)
      
  class StudentClass(Base):
      __tablename__ = 'StudentClasses'
      student_id = Column(Integer, ForeignKey('Students.ID', ondelete=&quot;CASCADE&quot;), primary_key=True)       
      CMClass_id = Column(Integer, ForeignKey('Classes.ID', ondelete=&quot;CASCADE&quot;), primary_key=True)
      attended = Column(Boolean)
      Student = relationship(&quot;Student&quot;, back_populates=&quot;CMClasses&quot;)
      CMClass = relationship(&quot;CMClass&quot;, back_populates=&quot;Students&quot;)
  
  </code></pre>
  <p>It all seems to work rather well honestly, except for the cascade delete. I've played around with the 'relationship' part of the two sub classes (Student and CMClass). I think that's where the issue lies, but honestly I'm just not sure how to set it up. The examples just use an association table, which seems to work a little differently from an association object.</p>