How to get excellent results from the Mongolian criteria?

I am very upset when I try to request the results of the Mongolian criteria and save only documents in which the field is different. And by doing this:

Books.all.distinct(:name)

.. returns only name fields, not documents.

Also using a loop uniq, as pointed out in another question, doesn't work here.

Books.all.uniq{|x| x.name} # Returns non-unique results

What am I missing here?

+5
source share
2 answers

I'm not sure I fully understand what you are trying to achieve? Is the name field in your database a unique constraint?

If so, you simply extract all the book names to get the books themselves, which you would call the base object.

, , . , groupby? , Books.all.group_by{|book| book.name}, -, , .

:

0

OP, , , .

, , 98 2

: " ". 98 , .

? , , - .uniq .

0

All Articles