Skip to content

Commit e527528

Browse files
authored
MONGOID-5180 Rails parity: Add #pick method (equivalent to pluck.first) (#5391)
* MONGOID-5180 Rails parity: Add #pick method (equivalent to pluck.first) * MONGOID-5180 extract method * MONGOID-5180 fix comment * MONGOID-5180 added docs * MONGOID-5180 fix typo
1 parent 9b66277 commit e527528

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

source/reference/queries.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,29 @@ Mongoid also has some helpful methods on criteria.
13711371
Band.length
13721372
Band.where(name: "FKA Twigs").size
13731373

1374+
* - ``Criteria#pick``
1375+
1376+
*Get the values from one document for the provided fields.
1377+
Returns nil for unset fields and for non-existent fields.*
1378+
1379+
*This method accepts the dot notation, thus permitting referencing
1380+
fields in embedded associations.*
1381+
1382+
*This method respects :ref:`field aliases <field-aliases>`,
1383+
including those defined in embedded documents.*
1384+
1385+
-
1386+
.. code-block:: ruby
1387+
1388+
Band.all.pick(:name)
1389+
1390+
Band.all.pick('cities.name')
1391+
1392+
# Using the earlier definition of Manager,
1393+
# expands out to "managers.name" in the query:
1394+
Band.all.pick('managers.n')
1395+
1396+
13741397
* - ``Criteria#pluck``
13751398

13761399
*Get all the values for the provided field.

0 commit comments

Comments
 (0)