Then use this line:
```OntologyVersion.where("state != 'done'").where("ontology_id IN (SELECT id FROM ontologies WHERE repository_id=?)", self.id)```