Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Select Distinct ( With Inline Code ) #379

ChrisLundquist opened this Issue · 1 comment

3 participants


I wanted to select distinct so I wrote this helper. I am not quite sure where it may fit in to the project. If it isn't something that should be included, please feel free to close this issue. If it is something interesting, please let me know where it should go.

== Distinct ==
module MongoMapperHelper
def distinct(field, conditions = {})
MongoMapper.database[self.collection_name].distinct(field, conditions

== Model ==
class Memory
extend MongoMapperHelper
include MongoMapper::Document
set_collection_name "memory"

key :ts, Date
key :h, String
key :i, String
key :t, String
key :ti, String
key :value, Integer

Loading development environment (Rails 3.1.3)
1.9.3-p0 :001 > Memory.distinct("h")
=> [""]
1.9.3-p0 :002 > Memory.distinct("h",:ti => "asdf")
=> []
1.9.3-p0 :003 > Memory.first
=> #
1.9.3-p0 :004 > Memory.distinct("h",:ti => "used")
=> [""]


Plucky supports this already. It just needs to be added to the plucky delegated methods.

@bkeepers bkeepers closed this in 2d807c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.