@@ -304,6 +304,61 @@ Mongoid 7 behavior:
304
304
end
305
305
306
306
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
+
307
362
Removed ``:drop_dups`` Option from Indexes
308
363
------------------------------------------
309
364
0 commit comments