public function testDeleteWithManyToMany() { $this->loadFixtures(['Books', 'Genres', 'BookGenres']); $book = Book::select()->where('id', 5)->with('Genres')->first(); $this->assertEquals(new Book(['id' => 5, 'series_id' => 1, 'name' => 'A Dance with Dragons', 'isbn' => '0-553-80147-3', 'released' => '2011-07-19', 'Genres' => new ModelCollection([new Genre(['id' => 3, 'name' => 'Action-Adventure', 'book_count' => 8, 'junction' => new Entity(['id' => 14, 'book_id' => 5, 'genre_id' => 3])]), new Genre(['id' => 5, 'name' => 'Horror', 'book_count' => 5, 'junction' => new Entity(['id' => 15, 'book_id' => 5, 'genre_id' => 5])]), new Genre(['id' => 8, 'name' => 'Fantasy', 'book_count' => 15, 'junction' => new Entity(['id' => 13, 'book_id' => 5, 'genre_id' => 8])])])]), $book); $this->assertEquals(1, $book->delete()); $book = Book::find(5); $this->assertFalse($book->exists()); // Related record is not deleted $genre = Genre::find(3); $this->assertEquals(new Genre(['id' => 3, 'name' => 'Action-Adventure', 'book_count' => 8]), $genre); // Junction records are deleted $repo = new Repository(['table' => 'books_genres']); $this->assertEquals(0, $repo->select()->where('book_id', 5)->count()); }