Plugin index

6 views
Skip to first unread message

Leif

unread,
Feb 7, 2012, 7:47:46 AM2/7/12
to MongoMapper
Hi

I have a couple of plugins where I used to do this:

module MongoMapper
module Plugins
module TestPlugin
included do
class_attribute :some_field
self.some_field ||= "testfield"
key some_field, Array, :default => [], :index => true
end
end
end
end

I cannot seem to figure out a proper way to define indexes in plugins,
as both the field name and the model name depends on where the plugin
was included.

Any tips?

Thanks,
Leif

John Nunemaker

unread,
Feb 7, 2012, 1:26:06 PM2/7/12
to mongo...@googlegroups.com
I would probably avoid defining indexes in plugins. At most, maybe have class methods that get included that create the indexes and then recommend that people call those class methods out of band.

Indexing at runtime can be dangerous.
--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at

Leif

unread,
Feb 10, 2012, 9:44:41 AM2/10/12
to MongoMapper
Thanks for the info John.

I'll just add to the docs that it's recommended to index whatever they
call the key they use in the plugin then :)
Reply all
Reply to author
Forward
0 new messages