mongoid / origin

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

1.0.11: calling inspect on Queryable clears selector #65

Closed jcollum closed 11 years ago

jcollum commented 11 years ago
class Criteria
  include Origin::Queryable 
end 

1.9.3p286 :011 > cr = Criteria.new
 => #<Criteria:0x007ffd48030550 @serializers={}, @driver=:moped, @aliases={}, @selector={}, @options={}> 
1.9.3p286 :012 > cr.where(name: 'Bob')
 => #<Criteria:0x007ffd4803b4a0 @serializers={}, @driver=:moped, @aliases={}, @selector={"name"=>"Bob"}, @options={}, @strategy=nil, @negating=nil> 
1.9.3p286 :013 > cr.inspect
 => "#<Criteria:0x007ffd48030550 @serializers={}, @driver=:moped, @aliases={}, @selector={}, @options={}>" 
1.9.3p286 :014 > cr.selector
 => {} 

Note that I put a where clause in and the selector was {"name"=>"Bob"} which is expected. Then I do an inspect and the selector is now empty.

rodrigosaito commented 11 years ago

It's not the inspect that are clearing the selector.

when you call:

cr.where(name: 'Bob')

you are not modifying your cr instance, the where methods returns a new instance of Criteria.

if you do something like this:

cr.where(name: 'Bob').inspect

the selector will be there....