

def delete(self):
    from aleph.model import Document, Reference
    from aleph.model import DocumentRecord, DocumentPage
    sq = db.session.query(Document.id)
    sq = sq.filter((Document.source_id == self.id))
    sq = sq.subquery()
    q = db.session.query(DocumentPage)
    q = q.filter(DocumentPage.document_id.in_(sq))
    q.delete(synchronize_session='fetch')
    q = db.session.query(DocumentRecord)
    q = q.filter(DocumentRecord.document_id.in_(sq))
    q.delete(synchronize_session='fetch')
    q = db.session.query(Reference)
    q = q.filter(Reference.document_id.in_(q))
    q.delete(synchronize_session='fetch')
    q = db.session.query(Document)
    q = q.filter((Document.source_id == self.id))
    q.delete(synchronize_session='fetch')
    db.session.delete(self)

dataset/ETHPy150Open pudo/aleph/aleph/model/source.py Source.delete/VarMisuse@161/183 `sq`->`q`