From 7092961f9a4686c52f13ecb6fc1bdf60215106e7 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 3 Apr 2024 14:51:07 -0400 Subject: [PATCH 01/10] DOCSP-35976: Delete One usage example --- .../includes/usage-examples/DeleteOneTest.php | 40 +++++++++++ docs/usage-examples.txt | 3 +- docs/usage-examples/deleteOne.txt | 66 +++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 docs/includes/usage-examples/DeleteOneTest.php create mode 100644 docs/usage-examples/deleteOne.txt diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php new file mode 100644 index 000000000..4bb74ac60 --- /dev/null +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -0,0 +1,40 @@ + 'Capote', + 'runtime' => 114 + ], + ]); + + // begin-delete-one + $deleted = Movie::where('title', 'Capote') + ->orderBy('_id') + ->first() + ->delete(); + + echo 'Deleted documents: ' . $deleted; + // end-delete-one + + $this->assertTrue($deleted); + $this->expectOutputString('Deleted documents: 1'); + } +} diff --git a/docs/usage-examples.txt b/docs/usage-examples.txt index 08dda77ea..9257e6e0f 100644 --- a/docs/usage-examples.txt +++ b/docs/usage-examples.txt @@ -71,4 +71,5 @@ calls the controller function and returns the result to a web interface. :titlesonly: :maxdepth: 1 - /usage-examples/updateOne \ No newline at end of file + /usage-examples/updateOne + /usage-examples/deleteOne \ No newline at end of file diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt new file mode 100644 index 000000000..33918bc5d --- /dev/null +++ b/docs/usage-examples/deleteOne.txt @@ -0,0 +1,66 @@ +.. _laravel-delete-one-usage: + +================= +Delete a Document +================= + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: delete one, remove, code example + +.. contents:: On this page + :local: + :backlinks: none + :depth: 1 + :class: singlecol + +You can delete a document in a collection by retrieving a single document and calling +the ``delete()`` method on an Eloquent model or a query builder. + +Pass a query filter to the ``where()`` method, sort the matching documents, and call the +``first()`` method to retrieve only the first document. Then, delete this matching document +by calling the ``delete()`` method. + +Example +------- + +This usage example performs the following actions: + +- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the + ``sample_mflix`` database. +- Updates a document from the ``movies`` collection that matches a query filter. + +The example calls the following methods on the ``Movie`` model: + +- ``where()``: matches documents in which the value of the ``title`` field is ``'Capote'``. +- ``orderBy()``: sorts matched documents by their ascending ``_id`` values. +- ``first()``: retrieves only the first matching document. +- ``delete()``: deletes the retrieved document. + +.. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/DeleteOneTest.php + :start-after: begin-delete-one + :end-before: end-delete-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Deleted documents: 1 + +For instructions on editing your Laravel application to run the usage example, see the +:ref:`Usage Example landing page `. + +.. tip:: + + To learn more about deleting documents with {+odm-short+}, see the `Deleting Models + `__ section of the + Laravel documentation. + From e15e104dc466fc1437cae97a21204ca2878c3e78 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 3 Apr 2024 18:53:15 +0000 Subject: [PATCH 02/10] apply phpcbf formatting --- docs/includes/usage-examples/DeleteOneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 4bb74ac60..dc0c5e3c0 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -21,7 +21,7 @@ public function testDeleteOne(): void Movie::insert([ [ 'title' => 'Capote', - 'runtime' => 114 + 'runtime' => 114, ], ]); From bbab077aa593432fa41f5869ec4c7182453afe10 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 3 Apr 2024 15:12:27 -0400 Subject: [PATCH 03/10] small edit --- docs/usage-examples/deleteOne.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 33918bc5d..15b77101c 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -31,7 +31,7 @@ This usage example performs the following actions: - Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the ``sample_mflix`` database. -- Updates a document from the ``movies`` collection that matches a query filter. +- Deletes a document from the ``movies`` collection that matches a query filter. The example calls the following methods on the ``Movie`` model: From cee53ffb55d504c941450e165ae9f3eab7852b89 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 3 Apr 2024 15:49:46 -0400 Subject: [PATCH 04/10] JS feedback --- docs/usage-examples/deleteOne.txt | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 15b77101c..584970a75 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -20,9 +20,9 @@ Delete a Document You can delete a document in a collection by retrieving a single document and calling the ``delete()`` method on an Eloquent model or a query builder. -Pass a query filter to the ``where()`` method, sort the matching documents, and call the -``first()`` method to retrieve only the first document. Then, delete this matching document -by calling the ``delete()`` method. +To delete a document, pass a query filter to the ``where()`` method, sort the matching documents, +and call the ``first()`` method to retrieve only the first document. Then, delete this matching +document by calling the ``delete()`` method. Example ------- @@ -30,15 +30,15 @@ Example This usage example performs the following actions: - Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database. -- Deletes a document from the ``movies`` collection that matches a query filter. + ``sample_mflix`` database +- Deletes a document from the ``movies`` collection that matches a query filter The example calls the following methods on the ``Movie`` model: -- ``where()``: matches documents in which the value of the ``title`` field is ``'Capote'``. -- ``orderBy()``: sorts matched documents by their ascending ``_id`` values. -- ``first()``: retrieves only the first matching document. -- ``delete()``: deletes the retrieved document. +- ``where()``: matches documents in which the value of the ``title`` field is ``'Capote'`` +- ``orderBy()``: sorts matched documents by their ascending ``_id`` values +- ``first()``: retrieves only the first matching document +- ``delete()``: deletes the retrieved document .. io-code-block:: :copyable: true @@ -64,3 +64,6 @@ For instructions on editing your Laravel application to run the usage example, s `__ section of the Laravel documentation. + For more information about query filters, see the :ref:`laravel-retrieve-matching` section of + the Read Operations guide. + From eda988af2d1332074b3b008fb403f5aed7dd3193 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 4 Apr 2024 10:35:20 -0400 Subject: [PATCH 05/10] JT feedback --- docs/includes/usage-examples/DeleteOneTest.php | 6 +++--- docs/usage-examples/deleteOne.txt | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index dc0c5e3c0..b887f423e 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -20,13 +20,13 @@ public function testDeleteOne(): void Movie::truncate(); Movie::insert([ [ - 'title' => 'Capote', - 'runtime' => 114, + 'title' => 'Quiz Show', + 'runtime' => 133, ], ]); // begin-delete-one - $deleted = Movie::where('title', 'Capote') + $deleted = Movie::where('title', 'Quiz Show') ->orderBy('_id') ->first() ->delete(); diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 584970a75..9480a1fad 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -16,9 +16,9 @@ Delete a Document :backlinks: none :depth: 1 :class: singlecol - -You can delete a document in a collection by retrieving a single document and calling -the ``delete()`` method on an Eloquent model or a query builder. + +You can delete a document in a collection by retrieving a single Eloquent model and calling +the ``delete()`` method, or by calling ``delete()`` directly on a query builder. To delete a document, pass a query filter to the ``where()`` method, sort the matching documents, and call the ``first()`` method to retrieve only the first document. Then, delete this matching @@ -35,7 +35,7 @@ This usage example performs the following actions: The example calls the following methods on the ``Movie`` model: -- ``where()``: matches documents in which the value of the ``title`` field is ``'Capote'`` +- ``where()``: matches documents in which the value of the ``title`` field is ``'Quiz Show'`` - ``orderBy()``: sorts matched documents by their ascending ``_id`` values - ``first()``: retrieves only the first matching document - ``delete()``: deletes the retrieved document From 671993f4910c9c2342863bc81efef4d0c1d259e3 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 4 Apr 2024 11:26:13 -0400 Subject: [PATCH 06/10] JT feedback 2 --- docs/includes/usage-examples/DeleteOneTest.php | 2 +- docs/usage-examples/deleteOne.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index b887f423e..348f5530a 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -28,7 +28,7 @@ public function testDeleteOne(): void // begin-delete-one $deleted = Movie::where('title', 'Quiz Show') ->orderBy('_id') - ->first() + ->limit(1) ->delete(); echo 'Deleted documents: ' . $deleted; diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 9480a1fad..96759beb6 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -16,7 +16,7 @@ Delete a Document :backlinks: none :depth: 1 :class: singlecol - + You can delete a document in a collection by retrieving a single Eloquent model and calling the ``delete()`` method, or by calling ``delete()`` directly on a query builder. @@ -37,7 +37,7 @@ The example calls the following methods on the ``Movie`` model: - ``where()``: matches documents in which the value of the ``title`` field is ``'Quiz Show'`` - ``orderBy()``: sorts matched documents by their ascending ``_id`` values -- ``first()``: retrieves only the first matching document +- ``limit()``: retrieves only the first matching document - ``delete()``: deletes the retrieved document .. io-code-block:: From 2739d2fdd145e231efcfa680554404d2a3eb51e0 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Apr 2024 10:36:23 -0400 Subject: [PATCH 07/10] assertion edit --- docs/includes/usage-examples/DeleteOneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 348f5530a..196bfa486 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -35,6 +35,6 @@ public function testDeleteOne(): void // end-delete-one $this->assertTrue($deleted); - $this->expectOutputString('Deleted documents: 1'); + $this->expectOutputString('Deleted documents: true'); } } From c2f4d6e0f99aa2ac03b4ee8ec2759ec704d47af2 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Apr 2024 16:28:48 -0400 Subject: [PATCH 08/10] edit, code assertion --- docs/includes/usage-examples/DeleteOneTest.php | 4 ++-- docs/usage-examples/deleteOne.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 196bfa486..7c53b8b71 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -34,7 +34,7 @@ public function testDeleteOne(): void echo 'Deleted documents: ' . $deleted; // end-delete-one - $this->assertTrue($deleted); - $this->expectOutputString('Deleted documents: true'); + $this->assertCount(1, $deleted); + $this->expectOutputString('Deleted documents: 1'); } } diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 96759beb6..762cfd405 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -21,7 +21,7 @@ You can delete a document in a collection by retrieving a single Eloquent model the ``delete()`` method, or by calling ``delete()`` directly on a query builder. To delete a document, pass a query filter to the ``where()`` method, sort the matching documents, -and call the ``first()`` method to retrieve only the first document. Then, delete this matching +and call the ``limit()`` method to retrieve only the first document. Then, delete this matching document by calling the ``delete()`` method. Example From f552540ebd94e8038abb3e5b71fb8dc9401672ef Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Apr 2024 16:36:33 -0400 Subject: [PATCH 09/10] tests From c3213d4adb8485230212cedee5eb1d3c369f09c2 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 8 Apr 2024 16:39:30 -0400 Subject: [PATCH 10/10] assertion --- docs/includes/usage-examples/DeleteOneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 7c53b8b71..1a2acd4e0 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -34,7 +34,7 @@ public function testDeleteOne(): void echo 'Deleted documents: ' . $deleted; // end-delete-one - $this->assertCount(1, $deleted); + $this->assertEquals(1, $deleted); $this->expectOutputString('Deleted documents: 1'); } }