Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Select Distinct ( With Inline Code ) #379

Closed
ChrisLundquist opened this Issue · 1 comment

3 participants

@ChrisLundquist

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
end
end

== 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
end

==Usage==
Loading development environment (Rails 3.1.3)
1.9.3-p0 :001 > Memory.distinct("h")
=> ["cut.c45573.blueboxgrid.com"]
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")
=> ["cut.c45573.blueboxgrid.com"]

@brianhempel

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.