mongoid / origin

A Ruby DSL for building MongoDB queries
http://mongoid.org/en/origin/index.html
MIT License
62 stars 29 forks source link

Order without direction gives an unhelpful error message #86

Open gaffneyc opened 11 years ago

gaffneyc commented 11 years ago

If you fail to give a direction for an order you get this really unhelpful error message:

"field_one".__sort_option__
NoMethodError:
  undefined method `to_direction' for nil:NilClass

What would be the best approach here? Converting an app from another ORM that defaults to ascending order if not specified and was thinking of doing that.

If there is a preferred direction for this I'll put together a pull request with a fix.

sshaw commented 9 years ago

Agreed. Really this should be mentioned in one of[1] the Mongoid docs[2]. I had to do some DuckDuckGoing to even figure out it was an option, and issue searching to figure out the solution.

[1] http://rdoc.info/gems/mongoid/3.1.6/Mongoid/Relations/Macros/ClassMethods#has_many-instance_method [2]http://mongoid.org/en/mongoid/docs/relations.html