Skip to content

Commit 3b36b6d

Browse files
p-mongojohnnyshieldsp
authored
MONGOID-5391 improve pluck documentation, add tests (#5399)
* MONGOID-5391 improve documentation for pluck * additional tests Co-authored-by: shields <shields@tablecheck.com> Co-authored-by: Oleg Pudeyev <code@olegp.name>
1 parent c1e8b54 commit 3b36b6d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

source/reference/queries.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,12 +1412,20 @@ Mongoid also has some helpful methods on criteria.
14121412
.. code-block:: ruby
14131413

14141414
Band.all.pluck(:name)
1415+
#=> ["Daft Punk", "Aphex Twin", "Ween"]
14151416

1416-
Band.all.pluck('cities.name')
1417+
Band.all.pluck('address.city')
1418+
#=> ["Paris", "Limerick", "New Hope"]
14171419

14181420
# Using the earlier definition of Manager,
14191421
# expands out to "managers.name" in the query:
14201422
Band.all.pluck('managers.n')
1423+
#=> [ ["Berry Gordy", "Tommy Mottola"], [], ["Quincy Jones"] ]
1424+
1425+
# Accepts multiple field arguments, in which case
1426+
# the result will be returned as an Array of Arrays.
1427+
Band.all.pluck(:name, :likes)
1428+
#=> [ ["Daft Punk", 342], ["Aphex Twin", 98], ["Ween", 227] ]
14211429

14221430
* - ``Criteria#take``
14231431

0 commit comments

Comments
 (0)