File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ protected function ensureDeletable(Entity $entity): void
141141 protected function destroyShelf (Bookshelf $ shelf ): int
142142 {
143143 $ this ->destroyCommonRelations ($ shelf );
144+ $ shelf ->books ()->detach ();
144145 $ shelf ->forceDelete ();
145146
146147 return 1 ;
@@ -168,6 +169,7 @@ protected function destroyBook(Book $book): int
168169 }
169170
170171 $ this ->destroyCommonRelations ($ book );
172+ $ book ->shelves ()->detach ();
171173 $ book ->forceDelete ();
172174
173175 return $ count + 1 ;
Original file line number Diff line number Diff line change @@ -179,6 +179,34 @@ public function test_permanent_entity_delete_updates_existing_activity_with_enti
179179 ]);
180180 }
181181
182+ public function test_permanent_book_delete_removes_shelf_relation_data ()
183+ {
184+ $ book = $ this ->entities ->book ();
185+ $ shelf = $ this ->entities ->shelf ();
186+ $ shelf ->books ()->attach ($ book );
187+ $ this ->assertDatabaseHas ('bookshelves_books ' , ['book_id ' => $ book ->id ]);
188+
189+ $ this ->asEditor ()->delete ($ book ->getUrl ());
190+ $ deletion = $ book ->deletions ()->firstOrFail ();
191+ $ this ->asAdmin ()->delete ("/settings/recycle-bin/ {$ deletion ->id }" )->assertRedirect ();
192+
193+ $ this ->assertDatabaseMissing ('bookshelves_books ' , ['book_id ' => $ book ->id ]);
194+ }
195+
196+ public function test_permanent_shelf_delete_removes_book_relation_data ()
197+ {
198+ $ book = $ this ->entities ->book ();
199+ $ shelf = $ this ->entities ->shelf ();
200+ $ shelf ->books ()->attach ($ book );
201+ $ this ->assertDatabaseHas ('bookshelves_books ' , ['bookshelf_id ' => $ shelf ->id ]);
202+
203+ $ this ->asEditor ()->delete ($ shelf ->getUrl ());
204+ $ deletion = $ shelf ->deletions ()->firstOrFail ();
205+ $ this ->asAdmin ()->delete ("/settings/recycle-bin/ {$ deletion ->id }" )->assertRedirect ();
206+
207+ $ this ->assertDatabaseMissing ('bookshelves_books ' , ['bookshelf_id ' => $ shelf ->id ]);
208+ }
209+
182210 public function test_auto_clear_functionality_works ()
183211 {
184212 config ()->set ('app.recycle_bin_lifetime ' , 5 );
You can’t perform that action at this time.
0 commit comments