Created
September 23, 2015 17:15
-
-
Save bburdiliak/bef208807e8ba292e0c9 to your computer and use it in GitHub Desktop.
Environment: Mongoid v. 4.0.0.rc1. Solves problem when running db:mongoid:create_indexes or any other mongoid rake task doesn't take into account models defined in engines used by your main application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main_app/lib/tasks/load_model.rake | |
namespace :db do | |
namespace :mongoid do | |
# include models from engine | |
task :load_models do | |
Scraper::Engine.config.paths['app/models'].to_a.each do |path| | |
preload = ::Mongoid.preload_models | |
if preload.resizable? | |
files = preload.map { |model| "#{path}/#{model}.rb" } | |
else | |
files = Dir.glob("#{path}/**/*.rb") | |
end | |
files.sort.each do |file| | |
require_dependency(file) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice! Thanks