/**
  * utility shared between getBelongsToRecord and getHasManyRecords
  *
  * @param \PhalconRest\API\Relation $relation            
  * @return object
  */
 private function buildRelationQuery(\PhalconRest\API\Relation $relation)
 {
     $refModelNameSpace = $relation->getReferencedModel();
     $config = $this->getDI()->get('config');
     $modelNameSpace = $config['namespaces']['models'];
     $mm = $this->getDI()->get('modelsManager');
     $query = $mm->createBuilder()->from($refModelNameSpace);
     $columns = array();
     // hasOnes are auto merged
     // todo should this be controlled by entityWith?
     $list = $relation->getHasOnes();
     foreach ($list as $model) {
         $columns[] = $model . '.*';
         $query->leftJoin($model);
     }
     // Load the main record field at the end, so they are not overwritten
     $columns[] = $refModelNameSpace . ".*";
     $query->columns($columns);
     return $query;
 }
 /**
  * utility shared between getBelongsToRecord and getHasManyRecords
  *
  * @param \PhalconRest\API\Relation $relation            
  * @return object
  */
 private function buildRelationQuery(\PhalconRest\API\Relation $relation)
 {
     $refModelNameSpace = $relation->getReferencedModel();
     $config = $this->getDI()->get('config');
     $modelNameSpace = $config['namespaces']['models'];
     $mm = $this->getDI()->get('modelsManager');
     $query = $mm->createBuilder()->from($refModelNameSpace);
     $columns = array($refModelNameSpace . ".*");
     $foo = $relation->getParent();
     // join in parent record if specified
     if ($relation->getParent()) {
         $columns[] = $modelNameSpace . $relation->getParent() . '.*';
         $query->join($modelNameSpace . $relation->getParent());
     }
     $query->columns($columns);
     return $query;
 }