public function update(LinkOne $link) { if ($link->isChanged()) { $link->get()->{$this->getForeignKey()} = $link->getModel()->{$this->getKey()}; $link->getOriginal()->{$this->getForeignKey()} = null; } }
/** * @covers ::set * @covers ::get * @covers ::isChanged * @covers ::getOriginal */ public function testSet() { $model = new Country(); $model2 = new Country(); $link = new LinkOne(new City(), City::getRepo()->getRel('country'), $model); $this->assertFalse($link->isChanged()); $link->set($model); $this->assertFalse($link->isChanged()); $link->set($model2); $this->assertTrue($link->isChanged()); $this->assertSame($model2, $link->get()); $this->assertSame($model, $link->getOriginal()); }