示例#1
0
文件: HasOne.php 项目: harp-orm/harp
 public function update(LinkOne $link)
 {
     if ($link->isChanged()) {
         $link->get()->{$this->getForeignKey()} = $link->getModel()->{$this->getKey()};
         $link->getOriginal()->{$this->getForeignKey()} = null;
     }
 }
示例#2
0
 /**
  * @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());
 }