'Return a query of the job\'s state history for the job that created this hda.'

def _job_state_history_query(self, hda):

    session = self.app.model.context
    JobToOutputDatasetAssociation = model.JobToOutputDatasetAssociation
    JobStateHistory = model.JobStateHistory
    hda_id = hda.id
    query = session.query(JobToOutputDatasetAssociation, JobStateHistory).filter((JobToOutputDatasetAssociation.dataset_id == hda_id)).filter((JobStateHistory.job_id == JobToOutputDatasetAssociation.job_id)).enable_eagerloads(False)
    return query
