It might be better to select ontologies that are not done by `ontologies.where("state != 'done'")` and then select their latest versions.