|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System Reactor package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Steeve Andrian Salim |
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
|
13
|
|
|
|
|
14
|
|
|
namespace O2System\Reactor\Models\Sql\Relations; |
|
15
|
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
|
17
|
|
|
|
|
18
|
|
|
use O2System\Reactor\Models\Sql; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class BelongsToManyThrough |
|
22
|
|
|
* |
|
23
|
|
|
* @package O2System\Reactor\Models\Sql\Relations |
|
24
|
|
|
*/ |
|
25
|
|
|
class BelongsToManyThrough extends Sql\Relations\Abstracts\AbstractRelation |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* BelongsToManyThrough::getResult |
|
29
|
|
|
* |
|
30
|
|
|
* @return array|bool|\O2System\Reactor\Models\Sql\DataObjects\Result\Row |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getResult() |
|
33
|
|
|
{ |
|
34
|
|
|
if ($this->map->currentModel->row instanceof Sql\DataObjects\Result\Row) { |
|
|
|
|
|
|
35
|
|
|
$criteria = $this->map->currentModel->row->offsetGet($this->map->currentPrimaryKey); |
|
|
|
|
|
|
36
|
|
|
$field = $this->map->currentTable . '.' . $this->map->currentPrimaryKey; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$this->map->referenceModel->qb |
|
|
|
|
|
|
39
|
|
|
->select([ |
|
40
|
|
|
$this->map->referenceTable . '.*', |
|
41
|
|
|
]) |
|
42
|
|
|
->join($this->map->currentTable, implode(' = ', [ |
|
43
|
|
|
$this->map->currentTable . '.' . $this->map->currentPrimaryKey, |
|
44
|
|
|
$this->map->intermediaryTable . '.' . $this->map->intermediaryCurrentForeignKey, |
|
|
|
|
|
|
45
|
|
|
])) |
|
46
|
|
|
->join($this->map->referenceTable, implode(' = ', [ |
|
47
|
|
|
$this->map->referenceTable . '.' . $this->map->referencePrimaryKey, |
|
48
|
|
|
$this->map->intermediaryTable . '.' . $this->map->intermediaryReferenceForeignKey, |
|
|
|
|
|
|
49
|
|
|
])); |
|
50
|
|
|
|
|
51
|
|
|
if ($result = $this->map->intermediaryModel->find($criteria, $field)) { |
|
|
|
|
|
|
52
|
|
|
return $result; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return false; |
|
57
|
|
|
} |
|
58
|
|
|
} |