Should we update the origin docs? #4

Closed
arthurnn opened this Issue Dec 25, 2012 · 3 comments

Comments

Projects
None yet
3 participants
Contributor

arthurnn commented Dec 25, 2012

I could be missing something, but as far as I understood and tested, this wont work:

class Criteria
  include Origin::Queryable
end

criteria = Criteria.new
criteria.where(name: "Syd").gt(age: 10).desc(:created_at)

criteria.selector #=> { name: "Syd", age: { "$gt" => 10 }}
criteria.options  #=> { sort: { created_at: -1 }}

the right approach for it is:

class Criteria
  include Origin::Queryable
end

criteria = Criteria.new
criteria = criteria.where(name: "Syd").gt(age: 10).desc(:created_at)

criteria.selector #=> { name: "Syd", age: { "$gt" => 10 }}
criteria.options  #=> { sort: { created_at: -1 }}

as Origin doest not modify the object.

Looks like that the docs are bad everywhere, is this a bug? if so I can fix it and pull request in the next minutes, otherwise let me know..

jcollum commented Dec 25, 2012

Those two blocks of code seem nearly identical, other than criteria = criteria. in the second block.

Contributor

arthurnn commented Dec 25, 2012

criteria = criteria.where(name: "Syd").gt(age: 10).desc(:created_at)

thats the only change pretty much..

@arthurnn arthurnn referenced this issue in mongoid/mongoid-site Dec 25, 2012

Merged

fix for origin docs #198

jcollum commented Dec 25, 2012

OK I see what's going on now. It was looking like a typo. The where statement should either modify the criteria object or be renamed. Personally, something like add seems more readable:

criteria = Criteria.new
criteria.add(name: "Syd").gt(age: 10).desc(:created_at)

Also, I think the find should just take the criteria object:

collection.find(criteria)

But that is probably out of scope.

@durran durran closed this in 29a1435 Dec 25, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment