Пример #1
0
 public function testChangingBelongsToSideOfHasManyRelation()
 {
     $k1 = new K();
     $k2 = new K();
     $i = new I();
     $i->ks->add($k1);
     $i->ks->add($k2);
     $this->assertTrue($i->save());
     $this->assertEquals(2, $i->ks->count());
     $k1->i = null;
     $this->assertTrue($k1->save());
     $iId = $i->id;
     $i->forget();
     unset($i);
     $i = I::getById($iId);
     $this->assertEquals(1, $i->ks->count());
     $i->ks->removeByIndex(0);
     $this->assertTrue($i->save());
     $this->assertEquals(0, $i->ks->count());
     $k2Id = $k2->id;
     $k2->forget();
     unset($k2);
     $k2 = K::getById($k2Id);
     $this->assertTrue($k2->i->id < 0);
 }