|
5 | 5 | use Plasma\SQL\QueryBuilder;
|
6 | 6 | use Plasma\SQL\QueryExpressions\Fragment;
|
7 | 7 | use Ramsey\Uuid\Uuid;
|
| 8 | +use React\Promise\LazyPromise; |
8 | 9 | use React\Promise\Promise;
|
9 | 10 | use React\Promise\PromiseInterface;
|
10 | 11 | use Rx\Observable;
|
@@ -278,41 +279,43 @@ private function buildTree(array $row, InspectedEntityInterface $entity, string
|
278 | 279 | }
|
279 | 280 |
|
280 | 281 | if ($join->getType() === 'inner' && ($join->getLazy() === JoinInterface::IS_LAZY || $entity->getClass() === $join->getEntity()->getClass())) {
|
281 |
| - $tree[$join->getProperty()] = new Promise(function (callable $resolve, callable $reject) use ($row, $join, $tableKey): void { |
282 |
| - foreach ($join->getClause() as $clause) { |
283 |
| - if ($row[$this->tableAliases[$tableKey]][$clause->getLocalKey()] === null) { |
284 |
| - $resolve(null); |
285 |
| - |
286 |
| - return; |
| 282 | + $tree[$join->getProperty()] = new LazyPromise(function () use ($row, $join, $tableKey): PromiseInterface { |
| 283 | + return new Promise(function (callable $resolve, callable $reject) use ($row, $join, $tableKey): void { |
| 284 | + foreach ($join->getClause() as $clause) { |
| 285 | + if ($row[$this->tableAliases[$tableKey]][$clause->getLocalKey()] === null) { |
| 286 | + $resolve(null); |
| 287 | + |
| 288 | + return; |
| 289 | + } |
287 | 290 | }
|
288 |
| - } |
289 | 291 |
|
290 |
| - $where = []; |
291 |
| - |
292 |
| - foreach ($join->getClause() as $clause) { |
293 |
| - $onLeftSide = $clause->getForeignKey(); |
294 |
| - if ($clause->getForeignFunction() !== null) { |
295 |
| - /** @psalm-suppress PossiblyNullOperand */ |
296 |
| - $onLeftSide = new Fragment($clause->getForeignFunction() . '(' . $onLeftSide . ')'); |
297 |
| - } |
298 |
| - if ($clause->getForeignCast() !== null) { |
299 |
| - /** @psalm-suppress PossiblyNullOperand */ |
300 |
| - $onLeftSide = new Fragment('CAST(' . (string)$onLeftSide . ' AS ' . $clause->getForeignCast() . ')'); |
| 292 | + $where = []; |
| 293 | + |
| 294 | + foreach ($join->getClause() as $clause) { |
| 295 | + $onLeftSide = $clause->getForeignKey(); |
| 296 | + if ($clause->getForeignFunction() !== null) { |
| 297 | + /** @psalm-suppress PossiblyNullOperand */ |
| 298 | + $onLeftSide = new Fragment($clause->getForeignFunction() . '(' . $onLeftSide . ')'); |
| 299 | + } |
| 300 | + if ($clause->getForeignCast() !== null) { |
| 301 | + /** @psalm-suppress PossiblyNullOperand */ |
| 302 | + $onLeftSide = new Fragment('CAST(' . (string)$onLeftSide . ' AS ' . $clause->getForeignCast() . ')'); |
| 303 | + } |
| 304 | + |
| 305 | + $where[] = [ |
| 306 | + $onLeftSide, |
| 307 | + '=', |
| 308 | + $row[$this->tableAliases[$tableKey]][$clause->getLocalKey()], |
| 309 | + ]; |
301 | 310 | }
|
302 | 311 |
|
303 |
| - $where[] = [ |
304 |
| - $onLeftSide, |
305 |
| - '=', |
306 |
| - $row[$this->tableAliases[$tableKey]][$clause->getLocalKey()], |
307 |
| - ]; |
308 |
| - } |
309 |
| - |
310 |
| - $this->client |
311 |
| - ->getRepository($join->getEntity() |
312 |
| - ->getClass()) |
313 |
| - ->fetch($where, [], self::SINGLE) |
314 |
| - ->toPromise() |
315 |
| - ->then($resolve, $reject); |
| 312 | + $this->client |
| 313 | + ->getRepository($join->getEntity() |
| 314 | + ->getClass()) |
| 315 | + ->fetch($where, [], self::SINGLE) |
| 316 | + ->toPromise() |
| 317 | + ->then($resolve, $reject); |
| 318 | + }); |
316 | 319 | });
|
317 | 320 |
|
318 | 321 | continue;
|
|
0 commit comments