开发者

Are STI's still incompatible with Rails 3.1 rc?

I did a fresh install of Rails 3.1 rc, following the [Railcast][1] of Ryan Bates. It seems, every STI implementation throws the same error (described below). For every other model, no problems occur.

Is this a known issue? A bug perhaps? Or is there something missing on my end? Anyone experiencing the same error?

Media model is the STI. Event model inherits from the Media model. Model definitions:

class Media < ActiveRecord::Base
  belongs_to :user
  ....
end

class Event < Media
  ...
end

In console, I do:

ruby-1.9.2-p136 :009 > Event.count
Creating scope :page. Overwriting existing method Event.page.
ActiveRecord::StatementInvalid: PGError: ERROR:  relation "media" does not exist
LINE 4:              WHERE a.attrelid = '"media"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"media"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum

  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:958:in `async_exec'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:958:in `exec_no_cache'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:547:in `block in exec_query'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:222:in `block in log'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract_adapter.rb:217:in `log'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:546:in `exec_query'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:1057:in `column_definitions'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:736:in `columns'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:93:in `block (2 levels) in initialize'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:174:in `with_connection'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:90:in `block in initialize'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:104:in `yield'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:104:in `default'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/connection_pool.rb:104:in `block in initialize'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/base.rb:709:in `yield'
... 8 levels...
  from /Users/Chris/Sites/site_name.1/app/models/event.rb:1:in `<top (required)>'
  from /Users/Ch开发者_高级运维ris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:452:in `load'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:452:in `block in load_file'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:639:in `new_constants_in'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:451:in `load_file'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:338:in `require_or_load'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:489:in `load_missing_constant'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:181:in `block in const_missing'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:179:in `each'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activesupport-3.1.0.rc1/lib/active_support/dependencies.rb:179:in `const_missing'
  from (irb):9
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:44:in `start'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:8:in `start'
  from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/railties-3.1.0.rc1/lib/rails/commands.rb:40:in `<top (required)>'
  from script/rails:6:in `require' from script/rails:6:in


  [1]: http://railscasts.com/episodes/265-rails-3-1-overview


Ok, found the problem. Quite interesting actually. In 3.0+, 'media'.pluralize returns 'medias'. In 3.1, 'media'.pluralize returns 'media'.

This means, for 3.1, the singular form for media, would be medium.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜