Пример #1
0
 /**
  * Queries for has relation fields with a link model to self and sets the result to the provided result
  * @param array $result Model query result
  * @param integer $recursiveDepth Recursive depth for the queries
  * @param string $fieldName Name of the has field
  * @param zibo\library\orm\definition\field\HasField $field Definition of the field
  * @return array Model query result with the has fields
  */
 private function queryHasWithLinkModelToSelf(array $result, ModelMeta $meta, $recursiveDepth, $fieldName, HasField $field)
 {
     $locale = $this->getLocale();
     $primaryKey = DefinitionModelTable::PRIMARY_KEY;
     $foreignKeys = $meta->getRelationForeignKey($fieldName);
     $linkModel = $meta->getRelationLinkModel($fieldName);
     $isHasOne = $field instanceof HasOneField;
     foreach ($result as $index => $data) {
         $query = $linkModel->createQuery($recursiveDepth, $locale, $this->willIncludeUnlocalizedData);
         $query->setOperator(Condition::OPERATOR_OR);
         foreach ($foreignKeys as $foreignKey) {
             $query->addCondition('{' . $foreignKey->getName() . '} = %1%', $data->id);
         }
         if ($isHasOne) {
             $result[$index]->{$fieldName} = $this->queryHasOneWithLinkModelToSelf($query, $foreignKeys, $data->id);
         } else {
             $result[$index]->{$fieldName} = $this->queryHasManyWithLinkModelToSelf($query, $meta, $fieldName, $foreignKeys, $data->id);
         }
     }
     return $result;
 }