1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System PHP Framework 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\Database\DataObjects\Result; |
19
|
|
|
use O2System\Reactor\Models\Sql; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class HasManyThrough |
23
|
|
|
* |
24
|
|
|
* @package O2System\Reactor\Models\Sql\Relations |
25
|
|
|
*/ |
26
|
|
|
class HasManyThrough extends Sql\Relations\Abstracts\AbstractRelation |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Get Result |
30
|
|
|
* |
31
|
|
|
* @return Sql\DataObjects\Result|bool |
32
|
|
|
*/ |
33
|
|
|
public function getResult() |
34
|
|
|
{ |
35
|
|
|
// print_out($this->map); |
36
|
|
|
if ($this->map->pivotModel->row instanceof Sql\DataObjects\Result\Row) { |
|
|
|
|
37
|
|
|
$result = $this->map->pivotModel->qb |
38
|
|
|
->from($this->map->relationTable) |
39
|
|
|
->join($this->map->referenceTable, implode(' = ', [ |
40
|
|
|
$this->map->referencePrimaryKey, |
41
|
|
|
$this->map->relationForeignKey, |
|
|
|
|
42
|
|
|
])) |
43
|
|
|
->getWhere([$this->map->referencePrimaryKey => $this->map->pivotModel->row->offsetGet($this->map->pivotForeignKey)]); |
|
|
|
|
44
|
|
|
|
45
|
|
|
if ($result instanceof Result) { |
|
|
|
|
46
|
|
|
if ($result->count() > 0) { |
47
|
|
|
if ($this->map->relationModel instanceof Sql\Model) { |
|
|
|
|
48
|
|
|
return new Sql\DataObjects\Result($result, $this->map->relationModel); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return new Sql\DataObjects\Result($result, $this->map->pivotModel); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
} |