I have a big ass collection which uses the same collection which needs to be filter in different ways
class PaymentLog < ActiveRecord::Base
include MongoMapper::Document
set_collection_name "logs"
...
# default scope for payment activity
end
And for example this.
class SuspiciousActivityLog < ActiveRecord::Base
include MongoMapper::Document
set_collection_name "logs"
...
# default scope search for suspicious activity
end
Both use the same logs, but each needs a default search on the type field.
MongoMapper does not support default scope. As explain on the MongoMapper mailing list when hamin wanted to discuss how to add default scopes…
If you know that a default scope is the right solution for your problem, you can hack it using MongoMapper’s Single Collection Inheritance module as a model: