I've searched this group and google, but have not found the answer to my
question. If there is a post about it somewhere, I'd greatly appreciate
a link. I also started to dig into the rake code, but, frankly, didn't
understand it.
Question:
Why does it seem that :environment is required in order to have
ActiveRecord::Base.configurations populated with the contents of
database.yml.
Explanation:
namespace :phillip do
task :mytask do
ActiveRecord::Base.configurations.each_value do |config|
p config['database']
end
end
end
prints nothing. Yet
namespace :phillip do
task :mytask => :environment do
ActiveRecord::Base.configurations.each_value do |config|
p config['database']
end
end
end
outputs the database names in my database.yml file.
I understand that if I'm actually trying to do something, I'd need the
environment. But it seems that the configurations would be available
without knowing a specific environment.
namespace :phillip do
task :mytask => :environment do
ActiveRecord::Base.configurations.each_value do |config|
p config['database']
end
end
end
outputs the database names in my database.yml file.
I understand that if I'm actually trying to do something, I'd need the
environment. But it seems that the configurations would be available
without knowing a specific environment.
Well at a very basic level, ActiveRecord::Base.configurations isn't
going to populate itself. rails isn't even loaded if your task doesn't
depend on :environment
Well at a very basic level, ActiveRecord::Base.configurations isn't
going to populate itself. rails isn't even loaded if your task doesn't
depend on :environment
Fred
Thanks, Fred. I'm understanding now. I haven't ventured into rake until
now and didn't get it. I read through some of the rake docs, but
apparently didn't actually digest anything.