#1377 ✓not-applicable
Kevin Watt

dm-rails preloads models in any environment

Reported by Kevin Watt | July 26th, 2010 @ 02:12 AM

I needed to monkey patch it as follows to keep it from preloading so spork would work without preloading my models.

The rails code goes based on the config.cache_classes setting, perhaps dm-rails should as well.

module Rails
module DataMapper

def self.preload_models(app)
  #puts "rails env is #{Rails.env}"
  return if Rails.env == 'test'
  # doesnt solve it though!  Fuckkkkk!  something ELSE is still including them?

  app.config.paths.app.models.each do |path|
    Dir.glob("#{path}/**/*.rb").sort.each { |file| require_dependency file }
  end
  finalize
end

end end

example from /railties-3.0.0.beta4/lib/rails/application/finisher.rb

  initializer :eager_load! do
    if config.cache_classes && !$rails_rake_task
      ActiveSupport.run_load_hooks(:before_eager_load, self)
      eager_load!
    end
  end

Comments and changes to this ticket

  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) August 10th, 2010 @ 05:49 PM

    • State changed from “new” to “unconfirmed”
    • Assigned user set to “Martin Gamsjaeger (snusnu)”
  • Martin Gamsjaeger (snusnu)

    Martin Gamsjaeger (snusnu) October 24th, 2010 @ 08:00 AM

    • State changed from “unconfirmed” to “not-applicable”
    • Tag set to dm-rails

    Kevin,

    dm-rails must know about all models to be able to call DataMapper.finalize properly. This is necessary to have all foreign key properties setup correctly, and is independent from the rails environment in use. Unless I'm totally misunderstanding your issue, there's really no way around this.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tags

Pages