Skip to content

Commit

Permalink
Changing index rake task not to use the module descendents method
Browse files Browse the repository at this point in the history
  • Loading branch information
Durran Jordan and Les Hill and Paul Elliott and Tim Pope authored and durran committed Jul 29, 2010
1 parent 3529f95 commit f883577
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/mongoid/railties/database.rake
Expand Up @@ -57,7 +57,18 @@ namespace :db do
if not Rake::Task.task_defined?("db:create_indexes")
desc 'Create the indexes defined on your mongoid models'
task :create_indexes => :environment do
::Rails::Mongoid.index_children(Mongoid::Document.descendants)
documents = []
Dir.glob("app/models/**/*.rb").sort.each do |file|
model = file.match(/\/(\w+).rb$/)[1]
klass = model.classify.constantize
begin
documents << klass unless klass.embedded
rescue => e
# Just for non-mongoid objects that dont have the embedded
# attribute at the class level.
end
end
::Rails::Mongoid.index_children(documents)
end
end

Expand Down

0 comments on commit f883577

Please sign in to comment.