Skip to content

Commit 26f75f1

Browse files
authored
MONGOID-5003 Delegate Model#find with block argument to Enumerable#find (#5352)
* MONGOID-5003 Delegate Model#find with block argument to Enumerable#find * Update lib/mongoid/findable.rb
1 parent aa8f3f7 commit 26f75f1

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

source/release-notes/mongoid-8.0.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Mongoid 7 behavior:
305305

306306

307307
``#pluck`` on Embedded Criteria Returns ``nil`` Values
308-
------------------------------------------------
308+
------------------------------------------------------
309309

310310
Mongoid 8 fixes a bug where calling ``#pluck`` on a Mongoid::Criteria
311311
for embedded documents discarded nil values. This behavior was
@@ -573,3 +573,30 @@ Calling ``tally`` on the age field yields the following:
573573

574574
The ``tally`` method accepts the dot notation and field aliases. It also
575575
allows for tallying localized fields.
576+
577+
578+
``find`` delegates to ``Enumerable#find`` when given a block
579+
------------------------------------------------------------
580+
581+
When given a block, without ``_id`` arguments, ``find`` delegates to
582+
``Enumerable#find``. Consider the following model:
583+
584+
.. code::
585+
586+
class Band
587+
include Mongoid::Document
588+
field :name, type: String
589+
end
590+
591+
Band.create!(name: "Depeche Mode")
592+
Band.create!(name: "The Rolling Stones")
593+
594+
Calling ``find`` with a block returns the first document for which the block
595+
returns ``true``:
596+
597+
.. code::
598+
599+
Band.find do |b|
600+
b.name == "Depeche Mode"
601+
end
602+
# => #<Band _id: 62c58e383282a4cbe82bd74b, name: "Depeche Mode">

0 commit comments

Comments
 (0)