继Ryan Bates的[Railcast][1]之后,我重新安装了Rails 3.1 rc。似乎每个STI实现都会抛出相同的错误(如下所述)。对于其他所有模型,都不会出现任何问题。
这是一个已知的问题吗?也许是虫子?还是我这边少了什么?有人遇到同样的错误吗?
媒体模式是STI。事件模型继承自媒体模型。型号定义:
class Media < ActiveRecord::Base
belongs_to :user
....
end
class Event < Media
...
end
在控制台,我做:
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/Chris/.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
好的,找到问题了。实际上很有趣。在3.0+中,"media"。polyralize返回"medias"。在3.1中,"media"。polyralize返回"media(媒体)"。
这意味着,对于3.1,媒体的单数形式将是媒体。