-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:
Take this scenario
Consider the following model that is used to collect User rating on a web item.
class Rating
include Mongoid::Document
field :comment, :type => String
field :value, :type => Integer
field :email, :type => String
field :other
field :data
scope :rated_a, lambda
{|val| where(:value => val) }end
Now if you try to access the scope, after you specify only() criteria, you are no longer able to use a scope with an argument.
Rating.only(:_id, :value, :comment, :email).where(:email => 'joe@somewhere.com').rated_a(5)
This will return with:
ArgumentError: wrong number of arguments (1 for 0)
But this works:
Rating.where(:email => 'joe@somewhere.com').rated_a(5)
As well as this:
Rating.where(:email => 'joe@somewhere.com').rated_a(5).only(:_id, :value, :comment, :email)