Permalink
Browse files

Ensure loading of models in rake tasks, to allow for threadsafe execu…

…tion. Fixes #1236.
  • Loading branch information...
1 parent 16d6f2f commit 2ff10c9aa2a7812a7f23a26fcd314623541290cc @durran durran committed Oct 12, 2011
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/mongoid/railtie.rb
View
@@ -95,7 +95,14 @@ def self.generator
# environments.
initializer "preload all application models" do |app|
config.to_prepare do
- ::Rails::Mongoid.preload_models(app) unless $rails_rake_task
+ if $rails_rake_task
+ # We previously got rid of this, however in the case where
+ # threadsafe! is enabled we must load all models so things like
+ # creating indexes works properly.
+ ::Rails::Mongoid.load_models(app)
+ else
+ ::Rails::Mongoid.preload_models(app)
+ end
end
end

0 comments on commit 2ff10c9

Please sign in to comment.