private function loadRelations(\Model\Entity $entity) { $oneToMany = $entity->oneToMany(); if (!empty($oneToMany)) { foreach ($oneToMany as $table => $info) { $this->qb->resetQueryParts(); $this->qb->setParameters(array()); $this->qb->setMaxResults(null); $this->qb->setFirstResult(null); $alias = substr($table, 0, 1); $this->qb->select('*')->from($table, $alias); if (isset($info['middle'])) { $condition = 'middle.' . $info['middle_attribute'] . ' = ' . $alias . '.' . $info['attribute']; $this->qb->innerJoin($alias, $info['middle'], 'middle', $condition)->where('middle.' . $info['relation'] . ' = :attribute')->setParameter('attribute', $entity->getPKValue()); } else { $this->qb->where($info['attribute'] . ' = :attribute')->setParameter('attribute', $entity->getPKValue()); } $entity->{$table} = $this->entitiesFromArray($this->getResults(), false, '\\Model\\' . $info['class']); } } }