/** * @param LinkOne $link */ public function update(LinkOne $link) { parent::update($link); if ($link->isChanged()) { $path = $link->get()->getChildrenPath(); return $link->getModel()->setPathAndUpdateDescendants($path); } }
/** * @covers ::update */ public function testUpdate() { $rel = new BelongsTo('country', City::getRepo()->getConfig(), 'Harp\\Harp\\Test\\TestModel\\Country'); $model = new City(['countryId' => 2]); $foreign = new Country(['id' => 20]); $link = new LinkOne($model, $rel, $foreign); $rel->update($link); $this->assertEquals(20, $model->countryId); }