Skip to content

Commit 42886f4

Browse files
authored
MONGOID-5100 allow selector arguments for .exists? (#5466)
* MONGOID-5100 allow selector arguments for .exists? * MONGOID-5100 add examples to the docstrings * MONGOID-5100 add docs and release notes * Empty-Commit * MONGOID-5100 allow false to be passed * MONGOID-5100 update docs and docstrings * MONGOID-5100 remove false as a param * MONGOID-5100 put back nil/false * MONGOID-5100 fix memory tests and fix limit == 0
1 parent 9632227 commit 42886f4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

source/reference/queries.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,11 +1243,22 @@ Mongoid also has some helpful methods on criteria.
12431243
*Determine if any matching documents exist. Will return true if there
12441244
are 1 or more.*
12451245

1246+
``#exists?`` *now takes a number of argument types:*
1247+
1248+
- ``Hash``: *A hash of conditions.*
1249+
- ``Object``: *An _id to search for.*
1250+
- ``false``/``nil``: *Always returns false.*
1251+
12461252
-
12471253
.. code-block:: ruby
12481254

12491255
Band.exists?
12501256
Band.where(name: "Photek").exists?
1257+
Band.exists?(name: "Photek")
1258+
Band.exists?(BSON::ObjectId('6320d96a3282a48cfce9e72c'))
1259+
Band.exists?('6320d96a3282a48cfce9e72c')
1260+
Band.exists?(false)
1261+
Band.exists?(nil)
12511262

12521263
* - ``Criteria#fifth``
12531264

source/release-notes/mongoid-8.1.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,16 @@ raised when destroying or deleting, and not on saving or updating. See the
287287
section on :ref:`Read-only Documents <readonly-documents>` for more details.
288288

289289

290+
Added method parameters to ``#exists?``
291+
---------------------------------------
292+
293+
Mongoid 8.1 introduces method paramters to the ``Contextual#exists?`` method.
294+
An _id, a hash of conditions, or ``false``/``nil`` can now be included:
295+
296+
.. code:: ruby
297+
298+
Band.exists?
299+
Band.exists?(name: "The Rolling Stones")
300+
Band.exists?(BSON::ObjectId('6320d96a3282a48cfce9e72c'))
301+
Band.exists?(false) # always false
302+
Band.exists?(nil) # always false

0 commit comments

Comments
 (0)