Skip to content

Commit 54c30e1

Browse files
MONGOID-5390: Mongoid::Contextual::Memory#pluck should return nil values (#5331)
* MONGOID-5390: Mongoid::Contextual::Memory#pluck should return nil values. Conveniently, we can now use ActiveSupport's Array#pluck here, introduced in Rails 5.0. * Array.wrap not needed * Docs * Add release notes * Update mongoid-8.0.txt * Update mongoid-8.0.txt * Comment fix * Update docs/release-notes/mongoid-8.0.txt Co-authored-by: Oleg Pudeyev <[email protected]> * Update mongoid-8.0.txt * Update mongoid-8.0.txt * More fixes to readme * Change splat in doc * Make "when plucking a mix of empty and non-empty values" its own spec Co-authored-by: shields <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 336b130 commit 54c30e1

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

source/release-notes/mongoid-8.0.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,61 @@ Mongoid 7 behavior:
304304
end
305305

306306

307+
``#pluck`` on Embedded Criteria Returns ``nil`` Values
308+
------------------------------------------------
309+
310+
Mongoid 8 fixes a bug where calling ``#pluck`` on a Mongoid::Criteria
311+
for embedded documents discarded nil values. This behavior was
312+
inconsistent with both the ``#pluck`` method in ActiveSupport and
313+
with how ``#pluck`` works when reading documents from the database.
314+
315+
Mongoid 8.0 behavior:
316+
317+
.. code-block:: ruby
318+
319+
class Address
320+
include Mongoid::Document
321+
322+
embedded_in :mall
323+
324+
field :street, type: String
325+
end
326+
327+
class Mall
328+
include Mongoid::Document
329+
330+
embeds_many :addresses
331+
end
332+
333+
mall = Mall.create!
334+
mall.addresses.create!(street: "Elm Street")
335+
mall.addresses.create!(street: nil)
336+
337+
# Pluck from embedded document criteria
338+
mall.addresses.all.pluck(:street)
339+
#=> ['Elm Street', nil]
340+
341+
Mongoid 7 behavior, given the same setup:
342+
343+
.. code-block:: ruby
344+
345+
# Pluck from embedded document criteria
346+
mall.addresses.all.pluck(:street)
347+
#=> ['Elm Street']
348+
349+
For clarity, the following behavior is unchanged from Mongoid 7 to Mongoid 8.0:
350+
351+
.. code-block:: ruby
352+
353+
# Pluck from database
354+
Mall.all.pluck('addresses.street')
355+
#=> [ ['Elm Street', nil] ]
356+
357+
# Pluck using ActiveSupport Array#pluck
358+
mall.addresses.pluck(:street)
359+
#=> ['Elm Street', nil]
360+
361+
307362
Removed ``:drop_dups`` Option from Indexes
308363
------------------------------------------
309364

0 commit comments

Comments
 (0)