Mongoid 5.0.0
class Product
scope :phyical_goods_scope
def self.physical_goods
category_id = Category.where(name: "Physical Goods").last.id
all.where(category_id: category_id)
end
end
In this example, both the scope and the class method will generate the following:
{"find"=>"products", "filter"=>{"name"=>"Physical Goods"}}
It seems that any query done within a class method queries the class you are within regardless if you specify a different constant. In this example I'm trying to query for a specific Category and the name of the category instead gets associated with the constant Product.
In Mongoid 5.0.1, it just throws
NoMethodError (undefined method `with_default_scope' for {}:Hash)