Skip to content

mongoid & accessible_by #322

Closed
brewster1134 opened this Issue Mar 29, 2011 · 8 comments

3 participants

@brewster1134

when accessing the accessible_by method on my models, a mongoid criteria object is returned with the following: selector: {"$or"=>[]},, which leads to the error $or requires nonempty array.

>> Product.count
=> 10
>> a
=> #<Ability:0x10501b3e0 @aliased_actions={:update=>[:edit], :create=>[:new], :read=>[:index, :show]}, @rules=[#<CanCan::Rule:0x10501b368 @match_all=false, @subjects=[:all], @conditions={}, @actions=[:manage], @expanded_actions=[:manage], @block=nil, @base_behavior=true>]>
>> Product.accessible_by(a)
=> #<Mongoid::Criteria
    selector: {"$or"=>[]},
    options:  {},
    class:    Product,
    embedded: false>
>> Product.accessible_by(a).first
Mongo::OperationFailure: $or requires nonempty array

do i need to pass conditions through accessible_by to make a proper mongo query?

@ryanb
Owner
ryanb commented Mar 29, 2011

You shouldn't need to pass anything more to accessible_by. Looks like this is a bug in the mongoid model. Thanks for reporting this. I'll look into fixing it. BTW, which version of mongoid and mongodb are you using?

@brewster1134

oops meant to include that with my original post...
mongodb v1.6.6-pre- & mongoid gem 2.0.0.rc.8

i will be upgrading to 1.8 pretty soon and i will let you know if that fixes it.

@joshuabowers

I can verify that this behavior is present in mongodb 1.8.0 and mongoid 2.0.0.rc.8

@ryanb
Owner
ryanb commented Mar 30, 2011

@joshuabowers thanks for confirming, now time to research it.

@ryanb
Owner
ryanb commented Mar 30, 2011

fixing mongoid 'or' error - closed by e96cf5b

@ryanb ryanb closed this Mar 30, 2011
@ryanb
Owner
ryanb commented Mar 30, 2011

I released a new version with this fix. Try 1.6.4 and see if it's working.

@joshuabowers

Seems to be working in my environment. Thanks Ryan!

@brewster1134

working for me as well. now that is promptness!

@jhuckabee jhuckabee pushed a commit to jhuckabee/cancan that referenced this issue Jun 22, 2011
@ryanb fixing mongoid 'or' error - closes #322 e96cf5b
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.