hzamani / acts_as_relation

Multi table Inheritance for rails
http://hzamani.github.com/acts_as_relation/
MIT License
180 stars 58 forks source link

Migration error with eager loading #44

Closed enyachoke closed 10 years ago

enyachoke commented 11 years ago

Enabling causes migrations to fails

config.eager_load = true

With the following trace

rake aborted!
PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 5:                WHERE a.attrelid = '"users"'::regclass
                                          ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                FROM pg_attribute a LEFT JOIN pg_attrdef d
                  ON a.attrelid = d.adrelid AND a.attnum = d.adnum
               WHERE a.attrelid = '"users"'::regclass
                 AND a.attnum > 0 AND NOT a.attisdropped
               ORDER BY a.attnum
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `exec_no_cache'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:138:in `block in exec_query'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:137:in `exec_query'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:915:in `column_definitions'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/schema_statements.rb:174:in `columns'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:114:in `block in prepare_default_proc'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `yield'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/schema_cache.rb:56:in `columns'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:208:in `columns'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:253:in `content_columns'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/lib/active_record/acts_as_relation.rb:70:in `block (2 levels) in acts_as'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/lib/active_record/acts_as_relation.rb:112:in `include'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/lib/active_record/acts_as_relation.rb:112:in `block in acts_as'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/lib/active_record/acts_as_relation.rb:111:in `class_eval'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/lib/active_record/acts_as_relation.rb:111:in `acts_as'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/app/models/student.rb:10:in `<class:Student>'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/app/models/student.rb:1:in `<top (required)>'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:329:in `require_or_load'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:288:in `depend_on'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:206:in `require_dependency'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:464:in `each'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:464:in `block in eager_load!'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:462:in `each'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:462:in `eager_load!'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/engine.rb:347:in `eager_load!'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `each'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/achachiez/Code/Rails/Projects/Bespoke/bespoke_college/config/environment.rb:5:in `<top (required)>'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/home/achachiez/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

But eager loading should be enabled in production. Thanks for the good work. Please suggest how I can fix this or fix it.

sorsaffari commented 11 years ago

Facing the exact same issue when pushed to Heroku.

enyachoke commented 11 years ago

@sorsaffari For now you can just set

config.eager_load = false

In your production.rb. i looked at the code last night and I think when I get time I will try fix it.

shanemcd commented 11 years ago

I wouldn't recommend setting eager_load to false in production.

You can manually create the migration if needed. The only columns that are needed on the superclass are:

"#{association_name}_id"
"#{association_name}_type"

Relevant lines are here

cfregin commented 11 years ago

In Rails 4 config.eager_load should be ignored by rake task but isn't. There is already a pull request: https://github.com/rails/rails/pull/11389 It will be closed in Rails 4.0.1.