Ejemplo n.º 1
0
 /**
  * @return Entity[]
  */
 protected function loadResults()
 {
     if ($this->results === null) {
         $this->results = $this->query->all();
         $list = [];
         $key = $this->foreignKey;
         $setup = function () use(&$list, $key) {
             $list[] = $this->dataMapperArgs[2][$key];
         };
         foreach ($this->results as $result) {
             $setup->call($result);
         }
         $this->keys = $list;
     }
     return $this->results;
 }
Ejemplo n.º 2
0
 /**
  * @param DataMapper $data
  * @param callable|null $callback
  * @return mixed
  */
 protected function getResult(DataMapper $data, callable $callback = null)
 {
     $manager = $data->getEntityManager();
     $owner = $data->getEntityMapper();
     $related = $manager->resolveEntityMapper($this->entityClass);
     if ($this->foreignKey === null) {
         $this->foreignKey = $owner->getForeignKey();
     }
     $statement = new SQLStatement();
     $select = new EntityQuery($manager, $related, $statement);
     $select->where($this->foreignKey)->is($data->getColumn($owner->getPrimaryKey()));
     if ($this->queryCallback !== null || $callback !== null) {
         $query = new Query($statement);
         if ($this->queryCallback !== null) {
             ($this->queryCallback)($query);
         }
         if ($callback !== null) {
             $callback($query);
         }
     }
     return $this->hasMany ? $select->all() : $select->get();
 }