예제 #1
0
 public function testDeleteWithRelations()
 {
     // one-to-many, many-to-many
     App\Post::find(1)->deleteWithRelations();
     self::assertEquals(App\Post::where('id', 1)->count(), 0);
     self::assertEquals(App\Comment::where('post_id', 1)->count(), 0);
     self::assertEquals(DB::table('lv_post_tag')->where('post_id', 1)->count(), 0);
     // one-to-one
     App\Post::getDeleteDescriptor()->removeDescription('comments');
     App\Comment::getDeleteDescriptor()->add('post');
     App\Comment::find(4)->deleteWithRelations();
     self::assertEquals(App\Comment::where('id', 4)->count(), 0);
     self::assertEquals(App\Post::where('id', 2)->count(), 0);
     // db rollback
     $this->rollback();
 }