1: <?php
2:
3: namespace Alchemy\orm;
4:
5:
6: class OneToOne extends Relationship {
7:
8: 9: 10: 11: 12: 13: 14:
15: public function isParent() {
16: return $this->origin === $this->getForeignKey()->getSourceTable();
17: }
18:
19:
20: public function getRemoteColumnMap($origin) {
21: $map = $this->getForeignKey()->getNameMap();
22: $map = $this->isParent() ? array_flip($map) : $map;
23:
24: foreach ($map as $remote => &$local) {
25: $local = $origin->{$local};
26: }
27:
28: return $map;
29: }
30:
31:
32: public function set($origin, $remote) {
33: $this->assertDestinationType($remote);
34:
35: return $this->isParent()
36: ? $origin->cascadeForeignKey($remote, $this)
37: : $remote->cascadeForeignKey($origin, $this->getInverse());
38: }
39: }
40: