orslumen/record-cache — pull request #22 by arekk (2012-05-30 16:18:17+00:00)
Title: Circular reference error

Hi, during my application development I've spotted some circular reference error. When you observe cached ActiveModel some initialization is done while running rake tasks, eg. db:migration task. because table doesn't exists task will fail. I've fixed that issue, also fixed "already initialized constant STRING" warning. If you like thos changes feel free to merge it.

Below stack-trace:
```
Mysql2::Error: Table 'pink_Vrai873.users' doesn't exist: SHOW FIELDS FROM `users`
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `query'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `execute'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `log'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:239:in `log'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/mysql2_adapter.rb:283:in `execute'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/mysql2_adapter.rb:473:in `columns'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `initialize'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:185:in `with_connection'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:92:in `initialize'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `call'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `default'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `[]'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:106:in `initialize'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:717:in `call'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:717:in `default'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:717:in `[]'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/base.rb:717:in `columns_hash'
/home/pink/rails/poema/vendor/gems/record-cache/lib/record_cache/strategy/unique_index_cache.rb:16:in `parse'
/home/pink/rails/poema/vendor/gems/record-cache/lib/record_cache/dispatcher.rb:28:in `parse'
/home/pink/rails/poema/vendor/gems/record-cache/lib/record_cache/dispatcher.rb:28:in `map'
/home/pink/rails/poema/vendor/gems/record-cache/lib/record_cache/dispatcher.rb:28:in `parse'
/home/pink/rails/poema/vendor/gems/record-cache/lib/record_cache/base.rb:126:in `cache_records'
/home/pink/rails/poema/app/models/user.rb:2
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:225:in `load_dependency'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:348:in `require_or_load'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:489:in `load_missing_constant'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in `const_missing'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `each'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `const_missing'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:113:in `constantize'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:112:in `each'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:112:in `constantize'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/core_ext/string/inflections.rb:43:in `constantize'
/home/pink/.gems/1.8/gems/activemodel-3.1.1/lib/active_model/observing.rb:189:in `observe'
/home/pink/.gems/1.8/gems/activemodel-3.1.1/lib/active_model/observing.rb:189:in `collect!'
/home/pink/.gems/1.8/gems/activemodel-3.1.1/lib/active_model/observing.rb:189:in `observe'
/home/pink/rails/poema/app/models/search_index_observer.rb:2
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:225:in `load_dependency'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:348:in `require_or_load'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:489:in `load_missing_constant'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in `const_missing'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `each'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in `const_missing'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:113:in `constantize'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:112:in `each'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:112:in `constantize'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/core_ext/string/inflections.rb:43:in `constantize'
/home/pink/.gems/1.8/gems/activemodel-3.1.1/lib/active_model/observing.rb:86:in `instantiate_observer'
/home/pink/.gems/1.8/gems/activemodel-3.1.1/lib/active_model/observing.rb:59:in `instantiate_observers'
/home/pink/.gems/1.8/gems/activemodel-3.1.1/lib/active_model/observing.rb:59:in `each'
/home/pink/.gems/1.8/gems/activemodel-3.1.1/lib/active_model/observing.rb:59:in `instantiate_observers'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/railtie.rb:92
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
/home/pink/.gems/1.8/gems/activerecord-3.1.1/lib/active_record/railtie.rb:91
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:34:in `call'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:43:in `run_load_hooks'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `each'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/application/finisher.rb:56
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `run_initializers'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `send'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/pink/rails/poema/config/environment.rb:5
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
/home/pink/.gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/application.rb:83:in `require_environment!'
/home/pink/.gems/1.8/gems/railties-3.1.1/lib/rails/application.rb:193:in `initialize_tasks'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/share/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:607:in `invoke_prerequisites'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:596:in `invoke_with_call_chain'
/usr/share/ruby-enterprise-1.8.7-2010.02/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/local/bin/rake-1.8:19:in `load'
/usr/local/bin/rake-1.8:19
```