Compare commits
	
		
			No commits in common. "219b42f995b8e34432da4dde77e53e24b75d78dd" and "88a2a99527b51dfb240ec78ac7070dc36a1022b6" have entirely different histories.
		
	
	
		
			219b42f995
			...
			88a2a99527
		
	
		
| @ -276,12 +276,13 @@ class Select | ||||
|             return [(string) $table, $params]; | ||||
|         } | ||||
| 
 | ||||
|         if ($table instanceof Select) { | ||||
|         if ($table instanceof Select) | ||||
|         { | ||||
|             return $table->generateQuery(); | ||||
|         } | ||||
| 
 | ||||
|         if (isset($this->tableAliases[$table])) { | ||||
|             $queryString = $defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table); | ||||
|             $queryString = ($defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table)); | ||||
|             return [$queryString, $params]; | ||||
|         } | ||||
| 
 | ||||
| @ -294,17 +295,24 @@ class Select | ||||
|             return (string) $column; | ||||
|         } | ||||
| 
 | ||||
|         if (!is_array($column)) { | ||||
|             $column = [$this->table, $column]; | ||||
|         } | ||||
|         if (is_array($column)) { | ||||
|             $out = ''; | ||||
| 
 | ||||
|         list($tableName, $params) = $this->generateTable($column[0]); | ||||
|         $out = $tableName . '.' . Utils::backtick($column[1]); | ||||
|         if (!empty($column[2])) { | ||||
|             $out .= ' ' . Utils::backtick($column[2]); | ||||
|         } | ||||
|             if ($column[0]) { | ||||
|                 list($tableName, $params) = $this->generateTable($column[0]); | ||||
|                 $out .= $tableName . '.'; | ||||
|             } | ||||
| 
 | ||||
|         return $out; | ||||
|             $out .= Utils::backtick($column[1]); | ||||
| 
 | ||||
|             if (!empty($column[2])) { | ||||
|                 $out .= ' ' . Utils::backtick($column[2]); | ||||
|             } | ||||
| 
 | ||||
|             return $out; | ||||
|         } else { | ||||
|             return Utils::backtick($column); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private function generateColumns(): string | ||||
|  | ||||
| @ -148,7 +148,7 @@ class PersistentDataManager implements IPersistentDataManager | ||||
|                 $relations = array_intersect_key($relations, array_flip($withRelations)); | ||||
|             } | ||||
| 
 | ||||
|             $columns = array_merge($columns, $this->getRelationColumns($table, $relations, $withRelations)); | ||||
|             $columns = array_merge($columns, $this->getRelationColumns($relations, $withRelations)); | ||||
| 
 | ||||
|             $this->leftJoinRelations($select, $table, $relations, $withRelations); | ||||
|             $select->columns($columns); | ||||
| @ -159,22 +159,21 @@ class PersistentDataManager implements IPersistentDataManager | ||||
|         return $select; | ||||
|     } | ||||
| 
 | ||||
|     private function getRelationColumns(string $table, array $relations, array $withRelations): array | ||||
|     private function getRelationColumns(array $relations, array $withRelations): array | ||||
|     { | ||||
|         $columns = []; | ||||
| 
 | ||||
|         foreach ($relations as $relation => $relationType) { | ||||
|             $relationTableAlias = $table . '__' . $relation; | ||||
|             $relationTable = call_user_func([$relationType, 'getTable']); | ||||
|             foreach (call_user_func([$relationType, 'getFields']) as $relationField) { | ||||
|                 $columns[] = [$relationTableAlias, $relationField, $relation . '__' . $relationField]; | ||||
|                 $columns[] = [$relationTable, $relationField, $relation . '__' . $relationField]; | ||||
|             } | ||||
| 
 | ||||
|             $relationsOfRelation = call_user_func([$relationType, 'getRelations']); | ||||
|             if (count($withRelations)) { | ||||
|                 $relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations)); | ||||
|             } | ||||
|             $columns = array_merge($columns, $this->getRelationColumns($relationTable, $relationsOfRelation, $withRelations)); | ||||
|             $columns = array_merge($columns, $this->getRelationColumns($relationsOfRelation, $withRelations)); | ||||
|         } | ||||
| 
 | ||||
|         return $columns; | ||||
| @ -183,16 +182,14 @@ class PersistentDataManager implements IPersistentDataManager | ||||
|     private function leftJoinRelations(Select $select, string $table, array $relations, array $withRelations): void | ||||
|     { | ||||
|         foreach ($relations as $relation => $relationType) { | ||||
|             $relationTableAlias = $table . '__' . $relation; | ||||
|             $relationTable = call_user_func([$relationType, 'getTable']); | ||||
|             $select->setTableAliases([$relationTableAlias => $relationTable]); | ||||
|             $select->leftJoin($relationTableAlias, [$relationTableAlias, 'id'], '=', [$table, $relation . '_id']); | ||||
|             $select->leftJoin($relationTable, [$relationTable, 'id'], '=', [$table, $relation . '_id']); | ||||
| 
 | ||||
|             $relationsOfRelation = call_user_func([$relationType, 'getRelations']); | ||||
|             $nextOrderRelations = call_user_func([$relationType, 'getRelations']); | ||||
|             if (count($withRelations)) { | ||||
|                 $relationsOfRelation = array_intersect_key($relationsOfRelation, array_flip($withRelations)); | ||||
|                 $nextOrderRelations = array_intersect_key($nextOrderRelations, array_flip($withRelations)); | ||||
|             } | ||||
|             $this->leftJoinRelations($select, $relationTable, $relationsOfRelation, $withRelations); | ||||
|             $this->leftJoinRelations($select, $relationTable, $nextOrderRelations, $withRelations); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| @ -227,16 +224,12 @@ class PersistentDataManager implements IPersistentDataManager | ||||
| 
 | ||||
|                 next($data); | ||||
|             } else if (substr($key, 0, strlen($relation . '__')) === $relation . '__') { | ||||
|                 if ($data[$relation . '__id'] !== null) { | ||||
|                     $relationType = current($relations); | ||||
|                     $relationModel = new $relationType(); | ||||
|                     $this->fillWithData($data, $relationModel, $withRelations, $relation); | ||||
|                 $relationType = current($relations); | ||||
|                 $relationModel = new $relationType(); | ||||
|                 $this->fillWithData($data, $relationModel, $withRelations, $relation); | ||||
| 
 | ||||
|                     $method = 'set' . str_replace('_', '', ucwords($relation, '_')); | ||||
|                     $model->$method($relationModel); | ||||
|                 } else { | ||||
|                     next($data); | ||||
|                 } | ||||
|                 $method = 'set' . str_replace('_', '', ucwords($relation, '_')); | ||||
|                 $model->$method($relationModel); | ||||
| 
 | ||||
|                 next($relations); | ||||
|             } else { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user