|
@@ -3254,13 +3254,13 @@ class JoinLimitsMiddleware extends Middleware
|
3254
|
3254
|
$joinPath = array();
|
3255
|
3255
|
$tables = explode(',', $params['join'][$i]);
|
3256
|
3256
|
for ($depth = 0; $depth < min($maxDepth, count($tables)); $depth++) {
|
3257
|
|
- array_push($joinPath, $table);
|
|
3257
|
+ array_push($joinPath, $tables[$depth]);
|
3258
|
3258
|
$tableCount += 1;
|
3259
|
3259
|
if ($tableCount == $maxTables) {
|
3260
|
3260
|
break;
|
3261
|
3261
|
}
|
3262
|
3262
|
}
|
3263
|
|
- array_push($joinPaths, $joinPath);
|
|
3263
|
+ array_push($joinPaths, implode(',', $joinPath));
|
3264
|
3264
|
if ($tableCount == $maxTables) {
|
3265
|
3265
|
break;
|
3266
|
3266
|
}
|
|
@@ -4583,14 +4583,20 @@ class OrderingInfo
|
4583
|
4583
|
}
|
4584
|
4584
|
}
|
4585
|
4585
|
if (count($fields) == 0) {
|
4586
|
|
- $pk = $table->getPk();
|
4587
|
|
- if ($pk) {
|
4588
|
|
- $fields[] = [$pk->getName(), 'ASC'];
|
4589
|
|
- } else {
|
4590
|
|
- foreach ($table->getColumnNames() as $columnName) {
|
4591
|
|
- $fields[] = [$columnName, 'ASC'];
|
4592
|
|
- }
|
|
4586
|
+ return $this->getDefaultColumnOrdering($table);
|
|
4587
|
+ }
|
|
4588
|
+ return $fields;
|
|
4589
|
+ }
|
4593
|
4590
|
|
|
4591
|
+ public function getDefaultColumnOrdering(ReflectedTable $table): array
|
|
4592
|
+ {
|
|
4593
|
+ $fields = array();
|
|
4594
|
+ $pk = $table->getPk();
|
|
4595
|
+ if ($pk) {
|
|
4596
|
+ $fields[] = [$pk->getName(), 'ASC'];
|
|
4597
|
+ } else {
|
|
4598
|
+ foreach ($table->getColumnNames() as $columnName) {
|
|
4599
|
+ $fields[] = [$columnName, 'ASC'];
|
4594
|
4600
|
}
|
4595
|
4601
|
}
|
4596
|
4602
|
return $fields;
|
|
@@ -4875,6 +4881,7 @@ class RelationJoiner
|
4875
|
4881
|
public function __construct(ReflectionService $reflection, ColumnIncluder $columns)
|
4876
|
4882
|
{
|
4877
|
4883
|
$this->reflection = $reflection;
|
|
4884
|
+ $this->ordering = new OrderingInfo();
|
4878
|
4885
|
$this->columns = $columns;
|
4879
|
4886
|
}
|
4880
|
4887
|
|
|
@@ -4992,7 +4999,7 @@ class RelationJoiner
|
4992
|
4999
|
}
|
4993
|
5000
|
if ($habtmValues != null) {
|
4994
|
5001
|
$this->fillFkValues($t2, $newRecords, $habtmValues->fkValues);
|
4995
|
|
- $this->setHabtmValues($t1, $t3, $records, $habtmValues);
|
|
5002
|
+ $this->setHabtmValues($t1, $t2, $records, $habtmValues);
|
4996
|
5003
|
}
|
4997
|
5004
|
}
|
4998
|
5005
|
}
|
|
@@ -5067,8 +5074,12 @@ class RelationJoiner
|
5067
|
5074
|
$conditions[] = new ColumnCondition($fk, 'in', $pkValueKeys);
|
5068
|
5075
|
}
|
5069
|
5076
|
$condition = OrCondition::fromArray($conditions);
|
|
5077
|
+ $columnOrdering = array();
|
5070
|
5078
|
$limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
|
5071
|
|
- foreach ($db->selectAll($t2, $columnNames, $condition, array(), 0, $limit) as $record) {
|
|
5079
|
+ if ($limit != -1) {
|
|
5080
|
+ $columnOrdering = $this->ordering->getDefaultColumnOrdering($t2);
|
|
5081
|
+ }
|
|
5082
|
+ foreach ($db->selectAll($t2, $columnNames, $condition, $columnOrdering, 0, $limit) as $record) {
|
5072
|
5083
|
$records[] = $record;
|
5073
|
5084
|
}
|
5074
|
5085
|
}
|
|
@@ -5113,9 +5124,13 @@ class RelationJoiner
|
5113
|
5124
|
|
5114
|
5125
|
$pkIds = implode(',', array_keys($pkValues));
|
5115
|
5126
|
$condition = new ColumnCondition($t3->getColumn($fk1Name), 'in', $pkIds);
|
|
5127
|
+ $columnOrdering = array();
|
5116
|
5128
|
|
5117
|
5129
|
$limit = VariableStore::get("joinLimits.maxRecords") ?: -1;
|
5118
|
|
- $records = $db->selectAll($t3, $columnNames, $condition, array(), 0, $limit);
|
|
5130
|
+ if ($limit != -1) {
|
|
5131
|
+ $columnOrdering = $this->ordering->getDefaultColumnOrdering($t3);
|
|
5132
|
+ }
|
|
5133
|
+ $records = $db->selectAll($t3, $columnNames, $condition, $columnOrdering, 0, $limit);
|
5119
|
5134
|
foreach ($records as $record) {
|
5120
|
5135
|
$val1 = $record[$fk1Name];
|
5121
|
5136
|
$val2 = $record[$fk2Name];
|
|
@@ -5126,10 +5141,10 @@ class RelationJoiner
|
5126
|
5141
|
return new HabtmValues($pkValues, $fkValues);
|
5127
|
5142
|
}
|
5128
|
5143
|
|
5129
|
|
- private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t3, array &$records, HabtmValues $habtmValues) /*: void*/
|
|
5144
|
+ private function setHabtmValues(ReflectedTable $t1, ReflectedTable $t2, array &$records, HabtmValues $habtmValues) /*: void*/
|
5130
|
5145
|
{
|
5131
|
5146
|
$pkName = $t1->getPk()->getName();
|
5132
|
|
- $t3Name = $t3->getName();
|
|
5147
|
+ $t2Name = $t2->getName();
|
5133
|
5148
|
foreach ($records as $i => $record) {
|
5134
|
5149
|
$key = $record[$pkName];
|
5135
|
5150
|
$val = array();
|
|
@@ -5137,7 +5152,7 @@ class RelationJoiner
|
5137
|
5152
|
foreach ($fks as $fk) {
|
5138
|
5153
|
$val[] = $habtmValues->fkValues[$fk];
|
5139
|
5154
|
}
|
5140
|
|
- $records[$i][$t3Name] = $val;
|
|
5155
|
+ $records[$i][$t2Name] = $val;
|
5141
|
5156
|
}
|
5142
|
5157
|
}
|
5143
|
5158
|
}
|