1: <?php
2:
3: namespace PHPixie\ORM\Relationships\Type\OneTo\Type\One\Preloader;
4:
5: class Item extends \PHPixie\ORM\Relationships\Relationship\Implementation\Preloader\Result\Single
6: {
7: protected $map = array();
8:
9: protected function mapItems()
10: {
11: $ownerKey = $this->side->config()->ownerKey;
12: $idField = $this->modelConfig->idField;
13:
14: $fields = $this->result->getFields(array($idField, $ownerKey));
15: foreach($fields as $offset => $row) {
16: $id = $row[$idField];
17: $ownerId = $row[$ownerKey];
18:
19: $this->idOffsets[$id] = $offset;
20: $this->map[$ownerId] = $id;
21: }
22: }
23:
24: protected function getMappedIdFor($entity)
25: {
26: $id = $entity->id();
27:
28: if(!array_key_exists($id, $this->map)) {
29: return null;
30: }
31:
32: return $this->map[$id];
33: }
34: }
35: