1: <?php
2:
3: namespace PHPixie\ORM\Relationships\Type\ManyToMany;
4:
5: class Preloader extends \PHPixie\ORM\Relationships\Relationship\Implementation\Preloader\Result\Multiple\IdMap
6: {
7: protected $pivotResult;
8:
9: public function __construct($loaders, $side, $modelConfig, $result, $loader, $pivotResult)
10: {
11: $this->pivotResult = $pivotResult;
12: parent::__construct($loaders, $side, $modelConfig, $result, $loader);
13: }
14:
15: protected function mapItems()
16: {
17: $type = $this->side->type();
18: $opposing = $type === 'left' ? 'right' : 'left';
19:
20: $config = $this->side->config();
21:
22: $ownerIdField = $config->get($opposing.'PivotKey');
23: $itemIdField = $config->get($type.'PivotKey');
24:
25: $fields = $this->pivotResult->getFields(array($ownerIdField, $itemIdField));
26:
27: foreach ($fields as $pivotData) {
28: $id = $pivotData[$itemIdField];
29: $ownerId = $pivotData[$ownerIdField];
30: $this->pushToMap($ownerId, $id);
31: }
32:
33: $this->mapIdOffsets();
34: }
35: }
36: